// Decompiled on 周六 2月 22 19:31:49 CST 2025 with Zomboid Decompiler v0.1.3 using Vineflower.
package zombie.iso;

import java.awt.Rectangle;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Stack;
import java.util.function.Consumer;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.joml.Vector2i;
import se.krka.kahlua.integration.annotations.LuaMethod;
import se.krka.kahlua.vm.JavaFunction;
import se.krka.kahlua.vm.KahluaTable;
import se.krka.kahlua.vm.LuaClosure;
import zombie.Lua.LuaEventManager;
import zombie.Lua.LuaHookManager;
import zombie.Lua.LuaManager;
import zombie.ai.astar.Mover;
import zombie.characters.IsoGameCharacter;
import zombie.characters.IsoPlayer;
import zombie.characters.IsoSurvivor;
import zombie.characters.IsoZombie;
import zombie.core.Core;
import zombie.core.PerformanceSettings;
import zombie.core.Rand;
import zombie.core.SpriteRenderer;
import zombie.core.Translator;
import zombie.core.logger.ExceptionLogger;
import zombie.core.opengl.RenderThread;
import zombie.core.opengl.Shader;
import zombie.core.physics.WorldSimulation;
import zombie.core.profiling.PerformanceProfileProbe;
import zombie.core.profiling.PerformanceProfileProbeList;
import zombie.core.textures.ColorInfo;
import zombie.core.textures.Texture;
import zombie.core.textures.TextureDraw;
import zombie.core.utils.IntGrid;
import zombie.core.utils.OnceEvery;
import zombie.debug.DebugLog;
import zombie.debug.DebugOptions;
import zombie.debug.DebugType;
import zombie.debug.LineDrawer;
import zombie.erosion.utils.Noise2D;
import zombie.gameStates.GameLoadingState;
import zombie.input.JoypadManager;
import zombie.inventory.InventoryItem;
import zombie.inventory.InventoryItemFactory;
import zombie.iso.SpriteDetails.IsoFlagType;
import zombie.iso.SpriteDetails.IsoObjectType;
import zombie.iso.areas.BuildingScore;
import zombie.iso.areas.IsoBuilding;
import zombie.iso.areas.IsoRoom;
import zombie.iso.areas.IsoRoomExit;
import zombie.iso.objects.IsoDeadBody;
import zombie.iso.objects.IsoGenerator;
import zombie.iso.objects.IsoTree;
import zombie.iso.objects.IsoWindow;
import zombie.iso.objects.IsoWorldInventoryObject;
import zombie.iso.sprite.CorpseFlies;
import zombie.iso.sprite.IsoSprite;
import zombie.iso.sprite.IsoSpriteManager;
import zombie.iso.sprite.shapers.FloorShaper;
import zombie.iso.sprite.shapers.FloorShaperAttachedSprites;
import zombie.iso.sprite.shapers.FloorShaperDiamond;
import zombie.iso.weather.ClimateManager;
import zombie.iso.weather.fog.ImprovedFog;
import zombie.iso.weather.fx.IsoWeatherFX;
import zombie.iso.weather.fx.WeatherFxMask;
import zombie.network.GameClient;
import zombie.network.GameServer;
import zombie.network.ServerMap;
import zombie.network.ServerOptions;
import zombie.popman.NetworkZombieSimulator;
import zombie.savefile.ClientPlayerDB;
import zombie.savefile.PlayerDB;
import zombie.scripting.objects.VehicleScript;
import zombie.ui.UIManager;
import zombie.util.Type;
import zombie.vehicles.BaseVehicle;

public final class IsoCell {
    public static int MaxHeight = 8;
    private static Shader m_floorRenderShader;
    private static Shader m_wallRenderShader;
    public ArrayList<IsoGridSquare> Trees = new ArrayList();
    static final ArrayList<IsoGridSquare> stchoices = new ArrayList();
    public final IsoChunkMap[] ChunkMap = new IsoChunkMap[4];
    public final ArrayList<IsoBuilding> BuildingList = new ArrayList();
    private final ArrayList<IsoWindow> WindowList = new ArrayList();
    private final ArrayList<IsoMovingObject> ObjectList = new ArrayList();
    private final ArrayList<IsoPushableObject> PushableObjectList = new ArrayList();
    private final HashMap<Integer, BuildingScore> BuildingScores = new HashMap();
    private final ArrayList<IsoRoom> RoomList = new ArrayList();
    private final ArrayList<IsoObject> StaticUpdaterObjectList = new ArrayList();
    private final ArrayList<IsoZombie> ZombieList = new ArrayList();
    private final ArrayList<IsoGameCharacter> RemoteSurvivorList = new ArrayList();
    private final ArrayList<IsoMovingObject> removeList = new ArrayList();
    private final ArrayList<IsoMovingObject> addList = new ArrayList();
    private final ArrayList<IsoObject> ProcessIsoObject = new ArrayList();
    private final ArrayList<IsoObject> ProcessIsoObjectRemove = new ArrayList();
    private final ArrayList<InventoryItem> ProcessItems = new ArrayList();
    private final ArrayList<InventoryItem> ProcessItemsRemove = new ArrayList();
    private final ArrayList<IsoWorldInventoryObject> ProcessWorldItems = new ArrayList();
    public final ArrayList<IsoWorldInventoryObject> ProcessWorldItemsRemove = new ArrayList();
    private final IsoGridSquare[][] gridSquares = new IsoGridSquare[4][IsoChunkMap.ChunkWidthInTiles * IsoChunkMap.ChunkWidthInTiles * 8];
    public static final boolean ENABLE_SQUARE_CACHE = true;
    private int height;
    private int width;
    private int worldX;
    private int worldY;
    public IntGrid DangerScore;
    private boolean safeToAdd = true;
    private final Stack<IsoLightSource> LamppostPositions = new Stack();
    public final ArrayList<IsoRoomLight> roomLights = new ArrayList();
    private final ArrayList<IsoHeatSource> heatSources = new ArrayList();
    public final ArrayList<BaseVehicle> addVehicles = new ArrayList();
    public final ArrayList<BaseVehicle> vehicles = new ArrayList();
    public static final int ISOANGLEFACTOR = 3;
    private static final int ZOMBIESCANBUDGET = 10;
    private static final float NEARESTZOMBIEDISTSQRMAX = 150.0F;
    private int zombieScanCursor = 0;
    private final IsoZombie[] nearestVisibleZombie = new IsoZombie[4];
    private final float[] nearestVisibleZombieDistSqr = new float[4];
    private static Stack<BuildingScore> buildingscores = new Stack();
    static ArrayList<IsoGridSquare> GridStack = null;
    public static final int RTF_SolidFloor = 1;
    public static final int RTF_VegetationCorpses = 2;
    public static final int RTF_MinusFloorCharacters = 4;
    public static final int RTF_ShadedFloor = 8;
    public static final int RTF_Shadows = 16;
    private static final ArrayList<IsoGridSquare> ShadowSquares = new ArrayList(1000);
    private static final ArrayList<IsoGridSquare> MinusFloorCharacters = new ArrayList(1000);
    private static final ArrayList<IsoGridSquare> SolidFloor = new ArrayList(5000);
    private static final ArrayList<IsoGridSquare> ShadedFloor = new ArrayList(5000);
    private static final ArrayList<IsoGridSquare> VegetationCorpses = new ArrayList(5000);
    public static final IsoCell.PerPlayerRender[] perPlayerRender = new IsoCell.PerPlayerRender[4];
    private final int[] StencilXY = new int[]{0, 0, -1, 0, 0, -1, -1, -1, -2, -1, -1, -2, -2, -2, -3, -2, -2, -3, -3, -3};
    private final int[] StencilXY2z = new int[]{
        0, 0, -1, 0, 0, -1, -1, -1, -2, -1, -1, -2, -2, -2, -3, -2, -2, -3, -3, -3, -4, -3, -3, -4, -4, -4, -5, -4, -4, -5, -5, -5, -6, -5, -5, -6, -6, -6
    };
    public int StencilX1;
    public int StencilY1;
    public int StencilX2;
    public int StencilY2;
    private Texture m_stencilTexture = null;
    private final DiamondMatrixIterator diamondMatrixIterator = new DiamondMatrixIterator(123);
    private final Vector2i diamondMatrixPos = new Vector2i();
    public int DeferredCharacterTick = 0;
    private boolean hasSetupSnowGrid = false;
    private IsoCell.SnowGridTiles snowGridTiles_Square;
    private IsoCell.SnowGridTiles[] snowGridTiles_Strip;
    private IsoCell.SnowGridTiles[] snowGridTiles_Edge;
    private IsoCell.SnowGridTiles[] snowGridTiles_Cove;
    private IsoCell.SnowGridTiles snowGridTiles_Enclosed;
    private int m_snowFirstNonSquare = -1;
    private Noise2D snowNoise2D = new Noise2D();
    private IsoCell.SnowGrid snowGridCur;
    private IsoCell.SnowGrid snowGridPrev;
    private int snowFracTarget = 0;
    private long snowFadeTime = 0L;
    private float snowTransitionTime = 5000.0F;
    private int raport = 0;
    private static final int SNOWSHORE_NONE = 0;
    private static final int SNOWSHORE_N = 1;
    private static final int SNOWSHORE_E = 2;
    private static final int SNOWSHORE_S = 4;
    private static final int SNOWSHORE_W = 8;
    public boolean recalcFloors = false;
    static int wx;
    static int wy;
    final KahluaTable[] drag = new KahluaTable[4];
    final ArrayList<IsoSurvivor> SurvivorList = new ArrayList();
    private static Texture texWhite;
    private static IsoCell instance;
    private int currentLX = 0;
    private int currentLY = 0;
    private int currentLZ = 0;
    int recalcShading = 30;
    int lastMinX = -1234567;
    int lastMinY = -1234567;
    private float rainScroll;
    private int[] rainX = new int[4];
    private int[] rainY = new int[4];
    private Texture[] rainTextures = new Texture[5];
    private long[] rainFileTime = new long[5];
    private float rainAlphaMax = 0.6F;
    private float[] rainAlpha = new float[4];
    protected int rainIntensity = 0;
    protected int rainSpeed = 6;
    int lightUpdateCount = 11;
    public boolean bRendering = false;
    final boolean[] bHideFloors = new boolean[4];
    final int[] unhideFloorsCounter = new int[4];
    boolean bOccludedByOrphanStructureFlag = false;
    int playerPeekedRoomId = -1;
    final ArrayList<ArrayList<IsoBuilding>> playerOccluderBuildings = new ArrayList(4);
    final IsoBuilding[][] playerOccluderBuildingsArr = new IsoBuilding[4][];
    final int[] playerWindowPeekingRoomId = new int[4];
    final boolean[] playerHidesOrphanStructures = new boolean[4];
    final boolean[] playerCutawaysDirty = new boolean[4];
    final Vector2 tempCutawaySqrVector = new Vector2();
    ArrayList<Integer> tempPrevPlayerCutawayRoomIDs = new ArrayList();
    ArrayList<Integer> tempPlayerCutawayRoomIDs = new ArrayList();
    final IsoGridSquare[] lastPlayerSquare = new IsoGridSquare[4];
    final boolean[] lastPlayerSquareHalf = new boolean[4];
    final IsoDirections[] lastPlayerDir = new IsoDirections[4];
    final Vector2[] lastPlayerAngle = new Vector2[4];
    int hidesOrphanStructuresAbove = MaxHeight;
    final Rectangle buildingRectTemp = new Rectangle();
    final ArrayList<ArrayList<IsoBuilding>> zombieOccluderBuildings = new ArrayList(4);
    final IsoBuilding[][] zombieOccluderBuildingsArr = new IsoBuilding[4][];
    final IsoGridSquare[] lastZombieSquare = new IsoGridSquare[4];
    final boolean[] lastZombieSquareHalf = new boolean[4];
    final ArrayList<ArrayList<IsoBuilding>> otherOccluderBuildings = new ArrayList(4);
    final IsoBuilding[][] otherOccluderBuildingsArr = new IsoBuilding[4][];
    final int mustSeeSquaresRadius = 4;
    final int mustSeeSquaresGridSize = 10;
    final ArrayList<IsoGridSquare> gridSquaresTempLeft = new ArrayList(100);
    final ArrayList<IsoGridSquare> gridSquaresTempRight = new ArrayList(100);
    private IsoWeatherFX weatherFX;
    private int minX;
    private int maxX;
    private int minY;
    private int maxY;
    private int minZ;
    private int maxZ;
    private OnceEvery dangerUpdate = new OnceEvery(0.4F, false);
    private Thread LightInfoUpdate = null;
    private final Stack<IsoRoom> SpottedRooms = new Stack();
    private IsoZombie fakeZombieForHit;

    public static int getMaxHeight() {
        return MaxHeight;
    }

    public LotHeader getCurrentLotHeader() {
        IsoChunk isoChunk = this.getChunkForGridSquare((int)IsoCamera.CamCharacter.x, (int)IsoCamera.CamCharacter.y, (int)IsoCamera.CamCharacter.z);
        return isoChunk.lotheader;
    }

    public IsoChunkMap getChunkMap(int pl) {
        return this.ChunkMap[pl];
    }

    public IsoGridSquare getFreeTile(RoomDef def) {
        stchoices.clear();

        for (int int0 = 0; int0 < def.rects.size(); int0++) {
            RoomDef.RoomRect roomRect = (RoomDef.RoomRect)def.rects.get(int0);

            for (int int1 = roomRect.x; int1 < roomRect.x + roomRect.w; int1++) {
                for (int int2 = roomRect.y; int2 < roomRect.y + roomRect.h; int2++) {
                    IsoGridSquare isoGridSquare0 = this.getGridSquare(int1, int2, def.level);
                    if (isoGridSquare0 != null) {
                        isoGridSquare0.setCachedIsFree(false);
                        isoGridSquare0.setCacheIsFree(false);
                        if (isoGridSquare0.isFree(false)) {
                            stchoices.add(isoGridSquare0);
                        }
                    }
                }
            }
        }

        if (stchoices.isEmpty()) {
            return null;
        } else {
            IsoGridSquare isoGridSquare1 = (IsoGridSquare)stchoices.get(Rand.Next(stchoices.size()));
            stchoices.clear();
            return isoGridSquare1;
        }
    }

    public static Stack<BuildingScore> getBuildings() {
        return buildingscores;
    }

    public static void setBuildings(Stack<BuildingScore> scores) {
        buildingscores = scores;
    }

    public IsoZombie getNearestVisibleZombie(int playerIndex) {
        return this.nearestVisibleZombie[playerIndex];
    }

    public IsoChunk getChunkForGridSquare(int x, int y, int z) {
        int int0 = x;
        int int1 = y;

        for (int int2 = 0; int2 < IsoPlayer.numPlayers; int2++) {
            if (!this.ChunkMap[int2].ignore) {
                x = int0 - this.ChunkMap[int2].getWorldXMinTiles();
                y = int1 - this.ChunkMap[int2].getWorldYMinTiles();
                if (x >= 0 && y >= 0) {
                    IsoChunkMap isoChunkMap = this.ChunkMap[int2];
                    x /= 10;
                    isoChunkMap = this.ChunkMap[int2];
                    y /= 10;
                    IsoChunk isoChunk = null;
                    isoChunk = this.ChunkMap[int2].getChunk(x, y);
                    if (isoChunk != null) {
                        return isoChunk;
                    }
                }
            }
        }

        return null;
    }

    public IsoChunk getChunk(int _wx, int _wy) {
        for (int _int = 0; _int < IsoPlayer.numPlayers; _int++) {
            IsoChunkMap isoChunkMap = this.ChunkMap[_int];
            if (!isoChunkMap.ignore) {
                IsoChunk isoChunk = isoChunkMap.getChunk(_wx - isoChunkMap.getWorldXMin(), _wy - isoChunkMap.getWorldYMin());
                if (isoChunk != null) {
                    return isoChunk;
                }
            }
        }

        return null;
    }

    public IsoCell(int _width, int _height) {
        IsoWorld.instance.CurrentCell = this;
        instance = this;
        this.width = _width;
        this.height = _height;

        for (int _int = 0; _int < 4; _int++) {
            this.ChunkMap[_int] = new IsoChunkMap(this);
            this.ChunkMap[_int].PlayerID = _int;
            this.ChunkMap[_int].ignore = _int > 0;
            this.playerOccluderBuildings.add(new ArrayList(5));
            this.zombieOccluderBuildings.add(new ArrayList(5));
            this.otherOccluderBuildings.add(new ArrayList(5));
        }

        WorldReuserThread.instance.run();
    }

    public short getStencilValue(int x, int y, int z) {
        short[][][] short0 = perPlayerRender[IsoCamera.frameState.playerIndex].StencilValues;
        int int0 = 0;
        int int1 = 0;

        for (byte _byte = 0; _byte < this.StencilXY.length; _byte += 2) {
            int int2 = -z * 3;
            int int3 = x + int2 + this.StencilXY[_byte];
            int int4 = y + int2 + this.StencilXY[_byte + 1];
            if (int3 >= this.minX && int3 < this.maxX && int4 >= this.minY && int4 < this.maxY) {
                short[] short1 = short0[int3 - this.minX][int4 - this.minY];
                if (short1[0] != 0) {
                    if (int0 == 0) {
                        int0 = short1[0];
                        int1 = short1[1];
                    } else {
                        int0 = Math.min(short1[0], int0);
                        int1 = Math.max(short1[1], int1);
                    }
                }
            }
        }

        if (int0 == 0) {
            return 1;
        } else {
            return int0 > 10 ? (short)(int0 - 10) : (short)(int1 + 1);
        }
    }

    public void setStencilValue(int x, int y, int z, int stencil) {
        short[][][] short0 = perPlayerRender[IsoCamera.frameState.playerIndex].StencilValues;

        for (byte _byte = 0; _byte < this.StencilXY.length; _byte += 2) {
            int int0 = -z * 3;
            int int1 = x + int0 + this.StencilXY[_byte];
            int int2 = y + int0 + this.StencilXY[_byte + 1];
            if (int1 >= this.minX && int1 < this.maxX && int2 >= this.minY && int2 < this.maxY) {
                short[] short1 = short0[int1 - this.minX][int2 - this.minY];
                if (short1[0] == 0) {
                    short1[0] = (short)stencil;
                    short1[1] = (short)stencil;
                } else {
                    short1[0] = (short)Math.min(short1[0], stencil);
                    short1[1] = (short)Math.max(short1[1], stencil);
                }
            }
        }
    }

    public short getStencilValue2z(int x, int y, int z) {
        short[][][] short0 = perPlayerRender[IsoCamera.frameState.playerIndex].StencilValues;
        int int0 = 0;
        int int1 = 0;
        int int2 = -z * 3;

        for (byte _byte = 0; _byte < this.StencilXY2z.length; _byte += 2) {
            int int3 = x + int2 + this.StencilXY2z[_byte];
            int int4 = y + int2 + this.StencilXY2z[_byte + 1];
            if (int3 >= this.minX && int3 < this.maxX && int4 >= this.minY && int4 < this.maxY) {
                short[] short1 = short0[int3 - this.minX][int4 - this.minY];
                if (short1[0] != 0) {
                    if (int0 == 0) {
                        int0 = short1[0];
                        int1 = short1[1];
                    } else {
                        int0 = Math.min(short1[0], int0);
                        int1 = Math.max(short1[1], int1);
                    }
                }
            }
        }

        if (int0 == 0) {
            return 1;
        } else {
            return int0 > 10 ? (short)(int0 - 10) : (short)(int1 + 1);
        }
    }

    public void setStencilValue2z(int x, int y, int z, int stencil) {
        short[][][] short0 = perPlayerRender[IsoCamera.frameState.playerIndex].StencilValues;
        int int0 = -z * 3;

        for (byte _byte = 0; _byte < this.StencilXY2z.length; _byte += 2) {
            int int1 = x + int0 + this.StencilXY2z[_byte];
            int int2 = y + int0 + this.StencilXY2z[_byte + 1];
            if (int1 >= this.minX && int1 < this.maxX && int2 >= this.minY && int2 < this.maxY) {
                short[] short1 = short0[int1 - this.minX][int2 - this.minY];
                if (short1[0] == 0) {
                    short1[0] = (short)stencil;
                    short1[1] = (short)stencil;
                } else {
                    short1[0] = (short)Math.min(short1[0], stencil);
                    short1[1] = (short)Math.max(short1[1], stencil);
                }
            }
        }
    }

    public void CalculateVertColoursForTile(IsoGridSquare sqThis, int x, int y, int zz, int playerIndex) {
        IsoGridSquare isoGridSquare0 = !IsoGridSquare.getMatrixBit(sqThis.visionMatrix, 0, 0, 1) ? sqThis.nav[IsoDirections.NW.index()] : null;
        IsoGridSquare isoGridSquare1 = !IsoGridSquare.getMatrixBit(sqThis.visionMatrix, 1, 0, 1) ? sqThis.nav[IsoDirections.N.index()] : null;
        IsoGridSquare isoGridSquare2 = !IsoGridSquare.getMatrixBit(sqThis.visionMatrix, 2, 0, 1) ? sqThis.nav[IsoDirections.NE.index()] : null;
        IsoGridSquare isoGridSquare3 = !IsoGridSquare.getMatrixBit(sqThis.visionMatrix, 2, 1, 1) ? sqThis.nav[IsoDirections.E.index()] : null;
        IsoGridSquare isoGridSquare4 = !IsoGridSquare.getMatrixBit(sqThis.visionMatrix, 2, 2, 1) ? sqThis.nav[IsoDirections.SE.index()] : null;
        IsoGridSquare isoGridSquare5 = !IsoGridSquare.getMatrixBit(sqThis.visionMatrix, 1, 2, 1) ? sqThis.nav[IsoDirections.S.index()] : null;
        IsoGridSquare isoGridSquare6 = !IsoGridSquare.getMatrixBit(sqThis.visionMatrix, 0, 2, 1) ? sqThis.nav[IsoDirections.SW.index()] : null;
        IsoGridSquare isoGridSquare7 = !IsoGridSquare.getMatrixBit(sqThis.visionMatrix, 0, 1, 1) ? sqThis.nav[IsoDirections.W.index()] : null;
        this.CalculateColor(isoGridSquare0, isoGridSquare1, isoGridSquare7, sqThis, 0, playerIndex);
        this.CalculateColor(isoGridSquare1, isoGridSquare2, isoGridSquare3, sqThis, 1, playerIndex);
        this.CalculateColor(isoGridSquare4, isoGridSquare5, isoGridSquare3, sqThis, 2, playerIndex);
        this.CalculateColor(isoGridSquare6, isoGridSquare5, isoGridSquare7, sqThis, 3, playerIndex);
    }

    private Texture getStencilTexture() {
        if (this.m_stencilTexture == null) {
            this.m_stencilTexture = Texture.getSharedTexture("media/mask_circledithernew.png");
        }

        return this.m_stencilTexture;
    }

    public void DrawStencilMask() {
        Texture texture = this.getStencilTexture();
        if (texture != null) {
            zombie.IndieGL.glStencilMask(255);
            zombie.IndieGL.glClear(1280);
            int int0 = IsoCamera.getOffscreenWidth(IsoPlayer.getPlayerIndex()) / 2;
            int int1 = IsoCamera.getOffscreenHeight(IsoPlayer.getPlayerIndex()) / 2;
            int0 -= texture.getWidth() / (2 / Core.TileScale);
            int1 -= texture.getHeight() / (2 / Core.TileScale);
            zombie.IndieGL.enableStencilTest();
            zombie.IndieGL.enableAlphaTest();
            zombie.IndieGL.glAlphaFunc(516, 0.1F);
            zombie.IndieGL.glStencilFunc(519, 128, 255);
            zombie.IndieGL.glStencilOp(7680, 7680, 7681);
            zombie.IndieGL.glColorMask(false, false, false, false);
            texture.renderstrip(
                int0 - (int)IsoCamera.getRightClickOffX(),
                int1 - (int)IsoCamera.getRightClickOffY(),
                texture.getWidth() * Core.TileScale,
                texture.getHeight() * Core.TileScale,
                1.0F,
                1.0F,
                1.0F,
                1.0F,
                null
            );
            zombie.IndieGL.glColorMask(true, true, true, true);
            zombie.IndieGL.glStencilFunc(519, 0, 255);
            zombie.IndieGL.glStencilOp(7680, 7680, 7680);
            zombie.IndieGL.glStencilMask(127);
            zombie.IndieGL.glAlphaFunc(519, 0.0F);
            this.StencilX1 = int0 - (int)IsoCamera.getRightClickOffX();
            this.StencilY1 = int1 - (int)IsoCamera.getRightClickOffY();
            this.StencilX2 = this.StencilX1 + texture.getWidth() * Core.TileScale;
            this.StencilY2 = this.StencilY1 + texture.getHeight() * Core.TileScale;
        }
    }

    public void RenderTiles(int _MaxHeight) {
        IsoCell.s_performance.isoCellRenderTiles.invokeAndMeasure(this, Integer.valueOf(_MaxHeight), IsoCell::renderTilesInternal);
    }

    private void renderTilesInternal(int int1) {
        if (DebugOptions.instance.Terrain.RenderTiles.Enable.getValue()) {
            if (m_floorRenderShader == null) {
                RenderThread.invokeOnRenderContext(this::initTileShaders);
            }

            int int0 = IsoCamera.frameState.playerIndex;
            IsoPlayer isoPlayer = IsoPlayer.players[int0];
            isoPlayer.dirtyRecalcGridStackTime = isoPlayer.dirtyRecalcGridStackTime - zombie.GameTime.getInstance().getMultiplier() / 4.0F;
            IsoCell.PerPlayerRender perPlayerRenderx = this.getPerPlayerRenderAt(int0);
            perPlayerRenderx.setSize(this.maxX - this.minX + 1, this.maxY - this.minY + 1);
            long _long = System.currentTimeMillis();
            if (this.minX != perPlayerRenderx.minX
                || this.minY != perPlayerRenderx.minY
                || this.maxX != perPlayerRenderx.maxX
                || this.maxY != perPlayerRenderx.maxY) {
                perPlayerRenderx.minX = this.minX;
                perPlayerRenderx.minY = this.minY;
                perPlayerRenderx.maxX = this.maxX;
                perPlayerRenderx.maxY = this.maxY;
                isoPlayer.dirtyRecalcGridStack = true;
                WeatherFxMask.forceMaskUpdate(int0);
            }

            IsoCell.s_performance.renderTiles.recalculateAnyGridStacks.start();
            boolean _boolean = isoPlayer.dirtyRecalcGridStack;
            this.recalculateAnyGridStacks(perPlayerRenderx, (int)int1, int0, _long);
            IsoCell.s_performance.renderTiles.recalculateAnyGridStacks.end();
            this.DeferredCharacterTick++;
            IsoCell.s_performance.renderTiles.flattenAnyFoliage.start();
            this.flattenAnyFoliage(perPlayerRenderx, int0);
            IsoCell.s_performance.renderTiles.flattenAnyFoliage.end();
            if (this.SetCutawayRoomsForPlayer() || _boolean) {
                IsoGridStack isoGridStack = perPlayerRenderx.GridStacks;

                for (int int2 = 0; int2 < int1 + 1; int2++) {
                    GridStack = (ArrayList<IsoGridSquare>)isoGridStack.Squares.get(int2);

                    for (int int3 = 0; int3 < GridStack.size(); int3++) {
                        IsoGridSquare isoGridSquare = (IsoGridSquare)GridStack.get(int3);
                        isoGridSquare.setPlayerCutawayFlag(int0, this.IsCutawaySquare(isoGridSquare, _long), _long);
                    }
                }
            }

            IsoCell.s_performance.renderTiles.performRenderTiles.start();
            this.performRenderTiles(perPlayerRenderx, (int)int1, int0, _long);
            IsoCell.s_performance.renderTiles.performRenderTiles.end();
            this.playerCutawaysDirty[int0] = false;
            ShadowSquares.clear();
            MinusFloorCharacters.clear();
            ShadedFloor.clear();
            SolidFloor.clear();
            VegetationCorpses.clear();
            IsoCell.s_performance.renderTiles.renderDebugPhysics.start();
            this.renderDebugPhysics(int0);
            IsoCell.s_performance.renderTiles.renderDebugPhysics.end();
            IsoCell.s_performance.renderTiles.renderDebugLighting.start();
            this.renderDebugLighting(perPlayerRenderx, (int)int1);
            IsoCell.s_performance.renderTiles.renderDebugLighting.end();
        }
    }

    private void initTileShaders() {
        if (DebugLog.isEnabled(DebugType.Shader)) {
            DebugLog.Shader.debugln("Loading shader: \"floorTile\"");
        }

        m_floorRenderShader = new Shader("floorTile");
        if (DebugLog.isEnabled(DebugType.Shader)) {
            DebugLog.Shader.debugln("Loading shader: \"wallTile\"");
        }

        m_wallRenderShader = new Shader("wallTile");
    }

    private IsoCell.PerPlayerRender getPerPlayerRenderAt(int _int) {
        if (perPlayerRender[_int] == null) {
            perPlayerRender[_int] = new IsoCell.PerPlayerRender();
        }

        return perPlayerRender[_int];
    }

    private void recalculateAnyGridStacks(IsoCell.PerPlayerRender perPlayerRenderx, int int5, int int0, long _long) {
        IsoPlayer isoPlayer = IsoPlayer.players[int0];
        if (isoPlayer.dirtyRecalcGridStack) {
            isoPlayer.dirtyRecalcGridStack = false;
            IsoGridStack isoGridStack = perPlayerRenderx.GridStacks;
            boolean[][][] boolean0 = perPlayerRenderx.VisiOccludedFlags;
            boolean[][] boolean1 = perPlayerRenderx.VisiCulledFlags;
            int int1 = -1;
            int int2 = -1;
            int int3 = -1;
            WeatherFxMask.setDiamondIterDone(int0);

            for (int int4 = int5; int4 >= 0; int4--) {
                GridStack = (ArrayList<IsoGridSquare>)isoGridStack.Squares.get(int4);
                GridStack.clear();
                if (int4 < this.maxZ) {
                    if (DebugOptions.instance.Terrain.RenderTiles.NewRender.getValue()) {
                        DiamondMatrixIterator diamondMatrixIteratorx = this.diamondMatrixIterator.reset(this.maxX - this.minX);
                        IsoGridSquare isoGridSquare0 = null;
                        Vector2i vector2i = this.diamondMatrixPos;

                        while (diamondMatrixIteratorx.next(vector2i)) {
                            if (vector2i.y < this.maxY - this.minY + 1) {
                                isoGridSquare0 = this.ChunkMap[int0].getGridSquare(vector2i.x + this.minX, vector2i.y + this.minY, int4);
                                if (int4 == 0) {
                                    boolean0[vector2i.x][vector2i.y][0] = false;
                                    boolean0[vector2i.x][vector2i.y][1] = false;
                                    boolean1[vector2i.x][vector2i.y] = false;
                                }

                                if (isoGridSquare0 == null) {
                                    WeatherFxMask.addMaskLocation(null, vector2i.x + this.minX, vector2i.y + this.minY, int4);
                                } else {
                                    IsoChunk isoChunk0 = isoGridSquare0.getChunk();
                                    if (isoChunk0 != null && isoGridSquare0.IsOnScreen(true)) {
                                        WeatherFxMask.addMaskLocation(isoGridSquare0, vector2i.x + this.minX, vector2i.y + this.minY, int4);
                                        boolean boolean2 = this.IsDissolvedSquare(isoGridSquare0, int0);
                                        isoGridSquare0.setIsDissolved(int0, boolean2, _long);
                                        if (!isoGridSquare0.getIsDissolved(int0, _long)) {
                                            isoGridSquare0.cacheLightInfo();
                                            GridStack.add(isoGridSquare0);
                                        }
                                    }
                                }
                            }
                        }
                    } else {
                        for (int int6 = this.minY; int6 < this.maxY; int6++) {
                            int int7 = this.minX;
                            IsoGridSquare isoGridSquare1 = this.ChunkMap[int0].getGridSquare(int7, int6, int4);
                            int int8 = IsoDirections.E.index();

                            while (int7 < this.maxX) {
                                if (int4 == 0) {
                                    boolean0[int7 - this.minX][int6 - this.minY][0] = false;
                                    boolean0[int7 - this.minX][int6 - this.minY][1] = false;
                                    boolean1[int7 - this.minX][int6 - this.minY] = false;
                                }

                                if (isoGridSquare1 != null && isoGridSquare1.getY() != int6) {
                                    isoGridSquare1 = null;
                                }

                                byte byte0 = -1;
                                byte byte1 = -1;
                                IsoChunkMap isoChunkMap0 = this.ChunkMap[int0];
                                int int9 = this.ChunkMap[int0].WorldX - IsoChunkMap.ChunkGridWidth / 2;
                                isoChunkMap0 = this.ChunkMap[int0];
                                int int10 = int7 - int9 * 10;
                                isoChunkMap0 = this.ChunkMap[int0];
                                int9 = this.ChunkMap[int0].WorldY - IsoChunkMap.ChunkGridWidth / 2;
                                isoChunkMap0 = this.ChunkMap[int0];
                                int int11 = int6 - int9 * 10;
                                IsoChunkMap isoChunkMap1 = this.ChunkMap[int0];
                                int10 /= 10;
                                IsoChunkMap isoChunkMap2 = this.ChunkMap[int0];
                                int11 /= 10;
                                if (int10 != int1 || int11 != int2) {
                                    IsoChunk isoChunk1 = this.ChunkMap[int0].getChunkForGridSquare(int7, int6);
                                    if (isoChunk1 != null) {
                                        int3 = isoChunk1.maxLevel;
                                    }
                                }

                                int1 = int10;
                                int2 = int11;
                                if (int3 < int4) {
                                    int7++;
                                } else {
                                    if (isoGridSquare1 == null) {
                                        isoGridSquare1 = this.getGridSquare(int7, int6, int4);
                                        if (isoGridSquare1 == null) {
                                            isoGridSquare1 = this.ChunkMap[int0].getGridSquare(int7, int6, int4);
                                            if (isoGridSquare1 == null) {
                                                int7++;
                                                continue;
                                            }
                                        }
                                    }

                                    IsoChunk isoChunk2 = isoGridSquare1.getChunk();
                                    if (isoChunk2 != null && isoGridSquare1.IsOnScreen(true)) {
                                        WeatherFxMask.addMaskLocation(isoGridSquare1, isoGridSquare1.x, isoGridSquare1.y, int4);
                                        boolean boolean3 = this.IsDissolvedSquare(isoGridSquare1, int0);
                                        isoGridSquare1.setIsDissolved(int0, boolean3, _long);
                                        if (!isoGridSquare1.getIsDissolved(int0, _long)) {
                                            isoGridSquare1.cacheLightInfo();
                                            GridStack.add(isoGridSquare1);
                                        }
                                    }

                                    isoGridSquare1 = isoGridSquare1.nav[int8];
                                    int7++;
                                }
                            }
                        }
                    }
                }
            }

            this.CullFullyOccludedSquares(isoGridStack, boolean0, boolean1);
        }
    }

    private void flattenAnyFoliage(IsoCell.PerPlayerRender perPlayerRenderx, int int3) {
        short[][][] _short = perPlayerRenderx.StencilValues;
        boolean[][] _boolean = perPlayerRenderx.FlattenGrassEtc;

        for (int int0 = this.minY; int0 <= this.maxY; int0++) {
            for (int int1 = this.minX; int1 <= this.maxX; int1++) {
                _short[int1 - this.minX][int0 - this.minY][0] = 0;
                _short[int1 - this.minX][int0 - this.minY][1] = 0;
                _boolean[int1 - this.minX][int0 - this.minY] = false;
            }
        }

        for (int int2 = 0; int2 < this.vehicles.size(); int2++) {
            BaseVehicle baseVehicle = (BaseVehicle)this.vehicles.get(int2);
            if (!(baseVehicle.getAlpha(int3) <= 0.0F)) {
                for (int int4 = -2; int4 < 5; int4++) {
                    for (int int5 = -2; int5 < 5; int5++) {
                        int int6 = (int)baseVehicle.x + int5;
                        int int7 = (int)baseVehicle.y + int4;
                        if (int6 >= this.minX && int6 <= this.maxX && int7 >= this.minY && int7 <= this.maxY) {
                            _boolean[int6 - this.minX][int7 - this.minY] = true;
                        }
                    }
                }
            }
        }
    }

    private void performRenderTiles(IsoCell.PerPlayerRender perPlayerRenderx, int int1, int int3, long _long) {
        IsoGridStack isoGridStack = perPlayerRenderx.GridStacks;
        boolean[][] boolean0 = perPlayerRenderx.FlattenGrassEtc;
        Shader shader0;
        Shader shader1;
        if (Core.bDebug && !DebugOptions.instance.Terrain.RenderTiles.UseShaders.getValue()) {
            shader0 = null;
            shader1 = null;
        } else {
            shader0 = m_floorRenderShader;
            shader1 = m_wallRenderShader;
        }

        for (int int0 = 0; int0 < int1 + 1; int0++) {
            IsoCell.s_performance.renderTiles.PperformRenderTilesLayer pperformRenderTilesLayer = IsoCell.s_performance.renderTiles.performRenderTilesLayers
                .start(int0);
            GridStack = (ArrayList<IsoGridSquare>)isoGridStack.Squares.get(int0);
            ShadowSquares.clear();
            SolidFloor.clear();
            ShadedFloor.clear();
            VegetationCorpses.clear();
            MinusFloorCharacters.clear();
            zombie.IndieGL.glClear(256);
            if (int0 == 0 && DebugOptions.instance.Terrain.RenderTiles.Water.getValue() && DebugOptions.instance.Terrain.RenderTiles.WaterBody.getValue()) {
                pperformRenderTilesLayer.renderIsoWater.start();
                IsoWater.getInstance().render(GridStack, false);
                pperformRenderTilesLayer.renderIsoWater.end();
            }

            pperformRenderTilesLayer.renderFloor.start();

            for (int int2 = 0; int2 < GridStack.size(); int2++) {
                IsoGridSquare isoGridSquare0 = (IsoGridSquare)GridStack.get(int2);
                if (isoGridSquare0.chunk == null || !isoGridSquare0.chunk.bLightingNeverDone[int3]) {
                    isoGridSquare0.bFlattenGrassEtc = int0 == 0 && boolean0[isoGridSquare0.x - this.minX][isoGridSquare0.y - this.minY];
                    int int4 = isoGridSquare0.renderFloor(shader0);
                    if (!isoGridSquare0.getStaticMovingObjects().isEmpty()) {
                        int4 |= 2;
                        int4 |= 16;
                        if (isoGridSquare0.HasStairs()) {
                            int4 |= 4;
                        }
                    }

                    if (!isoGridSquare0.getWorldObjects().isEmpty()) {
                        int4 |= 2;
                    }

                    if (!isoGridSquare0.getLocalTemporaryObjects().isEmpty()) {
                        int4 |= 4;
                    }

                    for (int int5 = 0; int5 < isoGridSquare0.getMovingObjects().size(); int5++) {
                        IsoMovingObject isoMovingObject = (IsoMovingObject)isoGridSquare0.getMovingObjects().get(int5);
                        boolean boolean1 = isoMovingObject.bOnFloor;
                        if (boolean1 && isoMovingObject instanceof IsoZombie isoZombie) {
                            boolean1 = isoZombie.isProne();
                            if (!BaseVehicle.RENDER_TO_TEXTURE) {
                                boolean1 = false;
                            }
                        }

                        if (boolean1) {
                            int4 |= 2;
                        } else {
                            int4 |= 4;
                        }

                        int4 |= 16;
                    }

                    if (!isoGridSquare0.getDeferedCharacters().isEmpty()) {
                        int4 |= 4;
                    }

                    if (isoGridSquare0.hasFlies()) {
                        int4 |= 4;
                    }

                    if ((int4 & 1) != 0) {
                        SolidFloor.add(isoGridSquare0);
                    }

                    if ((int4 & 8) != 0) {
                        ShadedFloor.add(isoGridSquare0);
                    }

                    if ((int4 & 2) != 0) {
                        VegetationCorpses.add(isoGridSquare0);
                    }

                    if ((int4 & 4) != 0) {
                        MinusFloorCharacters.add(isoGridSquare0);
                    }

                    if ((int4 & 16) != 0) {
                        ShadowSquares.add(isoGridSquare0);
                    }
                }
            }

            pperformRenderTilesLayer.renderFloor.end();
            pperformRenderTilesLayer.renderPuddles.start();
            IsoPuddles.getInstance().render(SolidFloor, int0);
            pperformRenderTilesLayer.renderPuddles.end();
            if (int0 == 0 && DebugOptions.instance.Terrain.RenderTiles.Water.getValue() && DebugOptions.instance.Terrain.RenderTiles.WaterShore.getValue()) {
                pperformRenderTilesLayer.renderShore.start();
                IsoWater.getInstance().render(null, true);
                pperformRenderTilesLayer.renderShore.end();
            }

            if (!SolidFloor.isEmpty()) {
                pperformRenderTilesLayer.renderSnow.start();
                this.RenderSnow(int0);
                pperformRenderTilesLayer.renderSnow.end();
            }

            if (!GridStack.isEmpty()) {
                pperformRenderTilesLayer.renderBlood.start();
                this.ChunkMap[int3].renderBloodForChunks(int0);
                pperformRenderTilesLayer.renderBlood.end();
            }

            if (!ShadedFloor.isEmpty()) {
                pperformRenderTilesLayer.renderFloorShading.start();
                this.RenderFloorShading(int0);
                pperformRenderTilesLayer.renderFloorShading.end();
            }

            WorldMarkers.instance.renderGridSquareMarkers(perPlayerRenderx, int0, int3);
            if (DebugOptions.instance.Terrain.RenderTiles.Shadows.getValue()) {
                pperformRenderTilesLayer.renderShadows.start();
                this.renderShadows();
                pperformRenderTilesLayer.renderShadows.end();
            }

            if (DebugOptions.instance.Terrain.RenderTiles.Lua.getValue()) {
                pperformRenderTilesLayer.luaOnPostFloorLayerDraw.start();
                LuaEventManager.triggerEvent("OnPostFloorLayerDraw", int0);
                pperformRenderTilesLayer.luaOnPostFloorLayerDraw.end();
            }

            IsoMarkers.instance.renderIsoMarkers(perPlayerRenderx, int0, int3);
            IsoMarkers.instance.renderCircleIsoMarkers(perPlayerRenderx, int0, int3);
            if (DebugOptions.instance.Terrain.RenderTiles.VegetationCorpses.getValue()) {
                pperformRenderTilesLayer.vegetationCorpses.start();

                for (int int6 = 0; int6 < VegetationCorpses.size(); int6++) {
                    IsoGridSquare isoGridSquare1 = (IsoGridSquare)VegetationCorpses.get(int6);
                    isoGridSquare1.renderMinusFloor(this.maxZ, false, true, false, false, false, shader1);
                    isoGridSquare1.renderCharacters(this.maxZ, true, true);
                }

                pperformRenderTilesLayer.vegetationCorpses.end();
            }

            ImprovedFog.startRender(int3, int0);
            if (DebugOptions.instance.Terrain.RenderTiles.MinusFloorCharacters.getValue()) {
                pperformRenderTilesLayer.minusFloorCharacters.start();

                for (int int7 = 0; int7 < MinusFloorCharacters.size(); int7++) {
                    IsoGridSquare isoGridSquare2 = (IsoGridSquare)MinusFloorCharacters.get(int7);
                    IsoGridSquare isoGridSquare3 = isoGridSquare2.nav[IsoDirections.S.index()];
                    IsoGridSquare isoGridSquare4 = isoGridSquare2.nav[IsoDirections.E.index()];
                    boolean boolean2 = isoGridSquare3 != null && isoGridSquare3.getPlayerCutawayFlag(int3, _long);
                    boolean boolean3 = isoGridSquare2.getPlayerCutawayFlag(int3, _long);
                    boolean boolean4 = isoGridSquare4 != null && isoGridSquare4.getPlayerCutawayFlag(int3, _long);
                    this.currentLY = isoGridSquare2.getY() - this.minY;
                    this.currentLZ = int0;
                    ImprovedFog.renderRowsBehind(isoGridSquare2);
                    boolean boolean5 = isoGridSquare2.renderMinusFloor(this.maxZ, false, false, boolean2, boolean3, boolean4, shader1);
                    isoGridSquare2.renderDeferredCharacters(this.maxZ);
                    isoGridSquare2.renderCharacters(this.maxZ, false, true);
                    if (isoGridSquare2.hasFlies()) {
                        CorpseFlies.render(isoGridSquare2.x, isoGridSquare2.y, isoGridSquare2.z);
                    }

                    if (boolean5) {
                        isoGridSquare2.renderMinusFloor(this.maxZ, true, false, boolean2, boolean3, boolean4, shader1);
                    }
                }

                pperformRenderTilesLayer.minusFloorCharacters.end();
            }

            IsoMarkers.instance.renderIsoMarkersDeferred(perPlayerRenderx, int0, int3);
            ImprovedFog.endRender();
            pperformRenderTilesLayer.end();
        }
    }

    private void renderShadows() {
        boolean _boolean = Core.getInstance().getOptionCorpseShadows();

        for (int int0 = 0; int0 < ShadowSquares.size(); int0++) {
            IsoGridSquare isoGridSquare = (IsoGridSquare)ShadowSquares.get(int0);

            for (int int1 = 0; int1 < isoGridSquare.getMovingObjects().size(); int1++) {
                IsoMovingObject isoMovingObject0 = (IsoMovingObject)isoGridSquare.getMovingObjects().get(int1);
                IsoGameCharacter isoGameCharacter = Type.tryCastTo(isoMovingObject0, IsoGameCharacter.class);
                if (isoGameCharacter != null) {
                    isoGameCharacter.renderShadow(isoGameCharacter.getX(), isoGameCharacter.getY(), isoGameCharacter.getZ());
                } else {
                    BaseVehicle baseVehicle = Type.tryCastTo(isoMovingObject0, BaseVehicle.class);
                    if (baseVehicle != null) {
                        baseVehicle.renderShadow();
                    }
                }
            }

            if (_boolean) {
                for (int int2 = 0; int2 < isoGridSquare.getStaticMovingObjects().size(); int2++) {
                    IsoMovingObject isoMovingObject1 = (IsoMovingObject)isoGridSquare.getStaticMovingObjects().get(int2);
                    IsoDeadBody isoDeadBody = Type.tryCastTo(isoMovingObject1, IsoDeadBody.class);
                    if (isoDeadBody != null) {
                        isoDeadBody.renderShadow();
                    }
                }
            }
        }
    }

    private void renderDebugPhysics(int _int) {
        if (Core.bDebug && DebugOptions.instance.PhysicsRender.getValue()) {
            TextureDraw.GenericDrawer genericDrawer = WorldSimulation.getDrawer(_int);
            SpriteRenderer.instance.drawGeneric(genericDrawer);
        }
    }

    private void renderDebugLighting(IsoCell.PerPlayerRender perPlayerRenderx, int int1) {
        if (Core.bDebug && DebugOptions.instance.LightingRender.getValue()) {
            IsoGridStack isoGridStack = perPlayerRenderx.GridStacks;
            byte _byte = 1;

            for (int int0 = 0; int0 < int1 + 1; int0++) {
                GridStack = (ArrayList<IsoGridSquare>)isoGridStack.Squares.get(int0);

                for (int int2 = 0; int2 < GridStack.size(); int2++) {
                    IsoGridSquare isoGridSquare = (IsoGridSquare)GridStack.get(int2);
                    float float0 = IsoUtils.XToScreenExact((float)isoGridSquare.x + 0.3F, (float)isoGridSquare.y, 0.0F, 0);
                    float float1 = IsoUtils.YToScreenExact((float)isoGridSquare.x + 0.3F, (float)isoGridSquare.y, 0.0F, 0);
                    float float2 = IsoUtils.XToScreenExact((float)isoGridSquare.x + 0.6F, (float)isoGridSquare.y, 0.0F, 0);
                    float float3 = IsoUtils.YToScreenExact((float)isoGridSquare.x + 0.6F, (float)isoGridSquare.y, 0.0F, 0);
                    float float4 = IsoUtils.XToScreenExact((float)(isoGridSquare.x + 1), (float)isoGridSquare.y + 0.3F, 0.0F, 0);
                    float float5 = IsoUtils.YToScreenExact((float)(isoGridSquare.x + 1), (float)isoGridSquare.y + 0.3F, 0.0F, 0);
                    float float6 = IsoUtils.XToScreenExact((float)(isoGridSquare.x + 1), (float)isoGridSquare.y + 0.6F, 0.0F, 0);
                    float float7 = IsoUtils.YToScreenExact((float)(isoGridSquare.x + 1), (float)isoGridSquare.y + 0.6F, 0.0F, 0);
                    float float8 = IsoUtils.XToScreenExact((float)isoGridSquare.x + 0.6F, (float)(isoGridSquare.y + 1), 0.0F, 0);
                    float float9 = IsoUtils.YToScreenExact((float)isoGridSquare.x + 0.6F, (float)(isoGridSquare.y + 1), 0.0F, 0);
                    float float10 = IsoUtils.XToScreenExact((float)isoGridSquare.x + 0.3F, (float)(isoGridSquare.y + 1), 0.0F, 0);
                    float float11 = IsoUtils.YToScreenExact((float)isoGridSquare.x + 0.3F, (float)(isoGridSquare.y + 1), 0.0F, 0);
                    float float12 = IsoUtils.XToScreenExact((float)isoGridSquare.x, (float)isoGridSquare.y + 0.6F, 0.0F, 0);
                    float float13 = IsoUtils.YToScreenExact((float)isoGridSquare.x, (float)isoGridSquare.y + 0.6F, 0.0F, 0);
                    float float14 = IsoUtils.XToScreenExact((float)isoGridSquare.x, (float)isoGridSquare.y + 0.3F, 0.0F, 0);
                    float float15 = IsoUtils.YToScreenExact((float)isoGridSquare.x, (float)isoGridSquare.y + 0.3F, 0.0F, 0);
                    if (IsoGridSquare.getMatrixBit(isoGridSquare.visionMatrix, 0, 0, _byte)) {
                        LineDrawer.drawLine(float0, float1, float2, float3, 1.0F, 0.0F, 0.0F, 1.0F, 0);
                    }

                    if (IsoGridSquare.getMatrixBit(isoGridSquare.visionMatrix, 0, 1, _byte)) {
                        LineDrawer.drawLine(float2, float3, float4, float5, 1.0F, 0.0F, 0.0F, 1.0F, 0);
                    }

                    if (IsoGridSquare.getMatrixBit(isoGridSquare.visionMatrix, 0, 2, _byte)) {
                        LineDrawer.drawLine(float4, float5, float6, float7, 1.0F, 0.0F, 0.0F, 1.0F, 0);
                    }

                    if (IsoGridSquare.getMatrixBit(isoGridSquare.visionMatrix, 1, 2, _byte)) {
                        LineDrawer.drawLine(float6, float7, float8, float9, 1.0F, 0.0F, 0.0F, 1.0F, 0);
                    }

                    if (IsoGridSquare.getMatrixBit(isoGridSquare.visionMatrix, 2, 2, _byte)) {
                        LineDrawer.drawLine(float8, float9, float10, float11, 1.0F, 0.0F, 0.0F, 1.0F, 0);
                    }

                    if (IsoGridSquare.getMatrixBit(isoGridSquare.visionMatrix, 2, 1, _byte)) {
                        LineDrawer.drawLine(float10, float11, float12, float13, 1.0F, 0.0F, 0.0F, 1.0F, 0);
                    }

                    if (IsoGridSquare.getMatrixBit(isoGridSquare.visionMatrix, 2, 0, _byte)) {
                        LineDrawer.drawLine(float12, float13, float14, float15, 1.0F, 0.0F, 0.0F, 1.0F, 0);
                    }

                    if (IsoGridSquare.getMatrixBit(isoGridSquare.visionMatrix, 1, 0, _byte)) {
                        LineDrawer.drawLine(float14, float15, float0, float1, 1.0F, 0.0F, 0.0F, 1.0F, 0);
                    }
                }
            }
        }
    }

    private void CullFullyOccludedSquares(IsoGridStack isoGridStack, boolean[][][] boolean2, boolean[][] boolean0) {
        int int0 = 0;

        for (int int1 = 1; int1 < MaxHeight + 1; int1++) {
            int0 += ((ArrayList)isoGridStack.Squares.get(int1)).size();
        }

        if (int0 >= 500) {
            int int2 = 0;

            for (int int3 = MaxHeight; int3 >= 0; int3--) {
                GridStack = (ArrayList<IsoGridSquare>)isoGridStack.Squares.get(int3);

                for (int int4 = GridStack.size() - 1; int4 >= 0; int4--) {
                    IsoGridSquare isoGridSquare = (IsoGridSquare)GridStack.get(int4);
                    int int5 = isoGridSquare.getX() - int3 * 3 - this.minX;
                    int int6 = isoGridSquare.getY() - int3 * 3 - this.minY;
                    if (int5 < 0 || int5 >= boolean0.length) {
                        GridStack.remove(int4);
                    } else if (int6 >= 0 && int6 < boolean0[0].length) {
                        if (int3 < MaxHeight) {
                            boolean boolean1 = !boolean0[int5][int6];
                            if (boolean1) {
                                boolean1 = false;
                                if (int5 > 2) {
                                    if (int6 > 2) {
                                        boolean1 = !boolean2[int5 - 3][int6 - 3][0]
                                            || !boolean2[int5 - 3][int6 - 3][1]
                                            || !boolean2[int5 - 3][int6 - 2][0]
                                            || !boolean2[int5 - 2][int6 - 3][1]
                                            || !boolean2[int5 - 2][int6 - 2][0]
                                            || !boolean2[int5 - 2][int6 - 2][1]
                                            || !boolean2[int5 - 2][int6 - 1][0]
                                            || !boolean2[int5 - 1][int6 - 2][0]
                                            || !boolean2[int5 - 1][int6 - 1][1]
                                            || !boolean2[int5 - 1][int6 - 1][0]
                                            || !boolean2[int5 - 1][int6][0]
                                            || !boolean2[int5][int6 - 1][1]
                                            || !boolean2[int5][int6][0]
                                            || !boolean2[int5][int6][1];
                                    } else if (int6 > 1) {
                                        boolean1 = !boolean2[int5 - 3][int6 - 2][0]
                                            || !boolean2[int5 - 2][int6 - 2][0]
                                            || !boolean2[int5 - 2][int6 - 2][1]
                                            || !boolean2[int5 - 2][int6 - 1][0]
                                            || !boolean2[int5 - 1][int6 - 2][0]
                                            || !boolean2[int5 - 1][int6 - 1][1]
                                            || !boolean2[int5 - 1][int6 - 1][0]
                                            || !boolean2[int5 - 1][int6][0]
                                            || !boolean2[int5][int6 - 1][1]
                                            || !boolean2[int5][int6][0]
                                            || !boolean2[int5][int6][1];
                                    } else if (int6 > 0) {
                                        boolean1 = !boolean2[int5 - 2][int6 - 1][0]
                                            || !boolean2[int5 - 1][int6 - 1][1]
                                            || !boolean2[int5 - 1][int6 - 1][0]
                                            || !boolean2[int5 - 1][int6][0]
                                            || !boolean2[int5][int6 - 1][1]
                                            || !boolean2[int5][int6][0]
                                            || !boolean2[int5][int6][1];
                                    } else {
                                        boolean1 = !boolean2[int5 - 1][int6][0] || !boolean2[int5][int6][0] || !boolean2[int5][int6][1];
                                    }
                                } else if (int5 > 1) {
                                    if (int6 > 2) {
                                        boolean1 = !boolean2[int5 - 2][int6 - 3][1]
                                            || !boolean2[int5 - 2][int6 - 2][0]
                                            || !boolean2[int5 - 2][int6 - 2][1]
                                            || !boolean2[int5 - 2][int6 - 1][0]
                                            || !boolean2[int5 - 1][int6 - 2][0]
                                            || !boolean2[int5 - 1][int6 - 1][1]
                                            || !boolean2[int5 - 1][int6 - 1][0]
                                            || !boolean2[int5 - 1][int6][0]
                                            || !boolean2[int5][int6 - 1][1]
                                            || !boolean2[int5][int6][0]
                                            || !boolean2[int5][int6][1];
                                    } else if (int6 > 1) {
                                        boolean1 = !boolean2[int5 - 2][int6 - 2][0]
                                            || !boolean2[int5 - 2][int6 - 2][1]
                                            || !boolean2[int5 - 2][int6 - 1][0]
                                            || !boolean2[int5 - 1][int6 - 2][0]
                                            || !boolean2[int5 - 1][int6 - 1][1]
                                            || !boolean2[int5 - 1][int6 - 1][0]
                                            || !boolean2[int5 - 1][int6][0]
                                            || !boolean2[int5][int6 - 1][1]
                                            || !boolean2[int5][int6][0]
                                            || !boolean2[int5][int6][1];
                                    } else if (int6 > 0) {
                                        boolean1 = !boolean2[int5 - 2][int6 - 1][0]
                                            || !boolean2[int5 - 1][int6 - 1][1]
                                            || !boolean2[int5 - 1][int6 - 1][0]
                                            || !boolean2[int5 - 1][int6][0]
                                            || !boolean2[int5][int6 - 1][1]
                                            || !boolean2[int5][int6][0]
                                            || !boolean2[int5][int6][1];
                                    } else {
                                        boolean1 = !boolean2[int5 - 1][int6][0] || !boolean2[int5][int6][0] || !boolean2[int5][int6][1];
                                    }
                                } else if (int5 > 0) {
                                    if (int6 > 2) {
                                        boolean1 = !boolean2[int5 - 1][int6 - 2][0]
                                            || !boolean2[int5 - 1][int6 - 1][1]
                                            || !boolean2[int5 - 1][int6 - 1][0]
                                            || !boolean2[int5 - 1][int6][0]
                                            || !boolean2[int5][int6 - 1][1]
                                            || !boolean2[int5][int6][0]
                                            || !boolean2[int5][int6][1];
                                    } else if (int6 > 1) {
                                        boolean1 = !boolean2[int5 - 1][int6 - 2][0]
                                            || !boolean2[int5 - 1][int6 - 1][1]
                                            || !boolean2[int5 - 1][int6 - 1][0]
                                            || !boolean2[int5 - 1][int6][0]
                                            || !boolean2[int5][int6 - 1][1]
                                            || !boolean2[int5][int6][0]
                                            || !boolean2[int5][int6][1];
                                    } else if (int6 > 0) {
                                        boolean1 = !boolean2[int5 - 1][int6 - 1][1]
                                            || !boolean2[int5 - 1][int6 - 1][0]
                                            || !boolean2[int5 - 1][int6][0]
                                            || !boolean2[int5][int6 - 1][1]
                                            || !boolean2[int5][int6][0]
                                            || !boolean2[int5][int6][1];
                                    } else {
                                        boolean1 = !boolean2[int5 - 1][int6][0] || !boolean2[int5][int6][0] || !boolean2[int5][int6][1];
                                    }
                                } else if (int6 > 2) {
                                    boolean1 = !boolean2[int5][int6 - 1][1] || !boolean2[int5][int6][0] || !boolean2[int5][int6][1];
                                } else if (int6 > 1) {
                                    boolean1 = !boolean2[int5][int6 - 1][1] || !boolean2[int5][int6][0] || !boolean2[int5][int6][1];
                                } else if (int6 > 0) {
                                    boolean1 = !boolean2[int5][int6 - 1][1] || !boolean2[int5][int6][0] || !boolean2[int5][int6][1];
                                } else {
                                    boolean1 = !boolean2[int5][int6][0] || !boolean2[int5][int6][1];
                                }
                            }

                            if (!boolean1) {
                                GridStack.remove(int4);
                                boolean0[int5][int6] = true;
                                continue;
                            }
                        }

                        int2++;
                        boolean boolean3 = IsoGridSquare.getMatrixBit(isoGridSquare.visionMatrix, 0, 1, 1)
                            && isoGridSquare.getProperties().Is(IsoFlagType.cutW);
                        boolean boolean4 = IsoGridSquare.getMatrixBit(isoGridSquare.visionMatrix, 1, 0, 1)
                            && isoGridSquare.getProperties().Is(IsoFlagType.cutN);
                        boolean boolean5 = false;
                        if (boolean3 || boolean4) {
                            boolean5 = (
                                    (float)isoGridSquare.x > IsoCamera.frameState.CamCharacterX || (float)isoGridSquare.y > IsoCamera.frameState.CamCharacterY
                                )
                                && isoGridSquare.z >= (int)IsoCamera.frameState.CamCharacterZ;
                            if (boolean5) {
                                int int7 = (int)(isoGridSquare.CachedScreenX - IsoCamera.frameState.OffX);
                                int int8 = (int)(isoGridSquare.CachedScreenY - IsoCamera.frameState.OffY);
                                if (int7 + 32 * Core.TileScale <= this.StencilX1
                                    || int7 - 32 * Core.TileScale >= this.StencilX2
                                    || int8 + 32 * Core.TileScale <= this.StencilY1
                                    || int8 - 96 * Core.TileScale >= this.StencilY2) {
                                    boolean5 = false;
                                }
                            }
                        }

                        int int9 = 0;
                        if (boolean3 && !boolean5) {
                            int9++;
                            if (int5 > 0) {
                                boolean2[int5 - 1][int6][0] = true;
                                if (int6 > 0) {
                                    boolean2[int5 - 1][int6 - 1][1] = true;
                                }
                            }

                            if (int5 > 1 && int6 > 0) {
                                boolean2[int5 - 2][int6 - 1][0] = true;
                                if (int6 > 1) {
                                    boolean2[int5 - 2][int6 - 2][1] = true;
                                }
                            }

                            if (int5 > 2 && int6 > 1) {
                                boolean2[int5 - 3][int6 - 2][0] = true;
                                if (int6 > 2) {
                                    boolean2[int5 - 3][int6 - 3][1] = true;
                                }
                            }
                        }

                        if (boolean4 && !boolean5) {
                            int9++;
                            if (int6 > 0) {
                                boolean2[int5][int6 - 1][1] = true;
                                if (int5 > 0) {
                                    boolean2[int5 - 1][int6 - 1][0] = true;
                                }
                            }

                            if (int6 > 1 && int5 > 0) {
                                boolean2[int5 - 1][int6 - 2][1] = true;
                                if (int5 > 1) {
                                    boolean2[int5 - 2][int6 - 2][0] = true;
                                }
                            }

                            if (int6 > 2 && int5 > 1) {
                                boolean2[int5 - 2][int6 - 3][1] = true;
                                if (int5 > 2) {
                                    boolean2[int5 - 3][int6 - 3][0] = true;
                                }
                            }
                        }

                        if (IsoGridSquare.getMatrixBit(isoGridSquare.visionMatrix, 1, 1, 0)) {
                            int9++;
                            boolean2[int5][int6][0] = true;
                            boolean2[int5][int6][1] = true;
                        }

                        if (int9 == 3) {
                            boolean0[int5][int6] = true;
                        }
                    } else {
                        GridStack.remove(int4);
                    }
                }
            }
        }
    }

    public void RenderFloorShading(int zza) {
        if (DebugOptions.instance.Terrain.RenderTiles.IsoGridSquare.Floor.LightingOld.getValue()
            && !DebugOptions.instance.Terrain.RenderTiles.IsoGridSquare.Floor.Lighting.getValue()) {
            if (zza < this.maxZ && PerformanceSettings.LightingFrameSkip < 3) {
                if (!Core.bDebug || !DebugOptions.instance.DebugDraw_SkipWorldShading.getValue()) {
                    if (texWhite == null) {
                        texWhite = Texture.getWhite();
                    }

                    Texture texture = texWhite;
                    if (texture != null) {
                        int int0 = IsoCamera.frameState.playerIndex;
                        int int1 = (int)IsoCamera.frameState.OffX;
                        int int2 = (int)IsoCamera.frameState.OffY;

                        for (int int3 = 0; int3 < ShadedFloor.size(); int3++) {
                            IsoGridSquare isoGridSquare = (IsoGridSquare)ShadedFloor.get(int3);
                            if (isoGridSquare.getProperties().Is(IsoFlagType.solidfloor)) {
                                float float0 = 0.0F;
                                float float1 = 0.0F;
                                float float2 = 0.0F;
                                if (isoGridSquare.getProperties().Is(IsoFlagType.FloorHeightOneThird)) {
                                    float1 = -1.0F;
                                    float0 = -1.0F;
                                } else if (isoGridSquare.getProperties().Is(IsoFlagType.FloorHeightTwoThirds)) {
                                    float1 = -2.0F;
                                    float0 = -2.0F;
                                }

                                float float3 = IsoUtils.XToScreen(
                                    (float)isoGridSquare.getX() + float0, (float)isoGridSquare.getY() + float1, (float)zza + float2, 0
                                );
                                float float4 = IsoUtils.YToScreen(
                                    (float)isoGridSquare.getX() + float0, (float)isoGridSquare.getY() + float1, (float)zza + float2, 0
                                );
                                float3 -= (float)int1;
                                float4 -= (float)int2;
                                int int4 = isoGridSquare.getVertLight(0, int0);
                                int int5 = isoGridSquare.getVertLight(1, int0);
                                int int6 = isoGridSquare.getVertLight(2, int0);
                                int int7 = isoGridSquare.getVertLight(3, int0);
                                if (DebugOptions.instance.Terrain.RenderTiles.IsoGridSquare.Floor.LightingDebug.getValue()) {
                                    int4 = -65536;
                                    int5 = -65536;
                                    int6 = -16776961;
                                    int7 = -16776961;
                                }

                                texture.renderdiamond(
                                    float3 - (float)(32 * Core.TileScale),
                                    float4 + (float)(16 * Core.TileScale),
                                    (float)(64 * Core.TileScale),
                                    (float)(32 * Core.TileScale),
                                    int7,
                                    int4,
                                    int5,
                                    int6
                                );
                            }
                        }
                    }
                }
            }
        }
    }

    public boolean IsPlayerWindowPeeking(int playerIndex) {
        return this.playerWindowPeekingRoomId[playerIndex] != -1;
    }

    public boolean CanBuildingSquareOccludePlayer(IsoGridSquare square, int playerIndex) {
        ArrayList arrayList = (ArrayList)this.playerOccluderBuildings.get(playerIndex);

        for (int int0 = 0; int0 < arrayList.size(); int0++) {
            IsoBuilding isoBuilding = (IsoBuilding)arrayList.get(int0);
            int int1 = isoBuilding.getDef().getX();
            int int2 = isoBuilding.getDef().getY();
            int int3 = isoBuilding.getDef().getX2() - int1;
            int int4 = isoBuilding.getDef().getY2() - int2;
            this.buildingRectTemp.setBounds(int1 - 1, int2 - 1, int3 + 2, int4 + 2);
            if (this.buildingRectTemp.contains(square.getX(), square.getY())) {
                return true;
            }
        }

        return false;
    }

    public int GetEffectivePlayerRoomId() {
        int int0 = IsoCamera.frameState.playerIndex;
        int int1 = this.playerWindowPeekingRoomId[int0];
        if (IsoPlayer.players[int0] != null && IsoPlayer.players[int0].isClimbing()) {
            int1 = -1;
        }

        if (int1 != -1) {
            return int1;
        } else {
            IsoGridSquare isoGridSquare = IsoPlayer.players[int0].current;
            return isoGridSquare != null ? isoGridSquare.getRoomID() : -1;
        }
    }

    private boolean SetCutawayRoomsForPlayer() {
        int int0 = IsoCamera.frameState.playerIndex;
        IsoPlayer isoPlayer = IsoPlayer.players[int0];
        ArrayList arrayList = this.tempPrevPlayerCutawayRoomIDs;
        this.tempPrevPlayerCutawayRoomIDs = this.tempPlayerCutawayRoomIDs;
        this.tempPlayerCutawayRoomIDs = arrayList;
        this.tempPlayerCutawayRoomIDs.clear();
        IsoGridSquare isoGridSquare0 = isoPlayer.getSquare();
        if (isoGridSquare0 == null) {
            return false;
        } else {
            IsoBuilding isoBuilding = isoGridSquare0.getBuilding();
            int int1 = isoGridSquare0.getRoomID();
            boolean _boolean = false;
            if (int1 == -1) {
                if (this.playerWindowPeekingRoomId[int0] != -1) {
                    this.tempPlayerCutawayRoomIDs.add(this.playerWindowPeekingRoomId[int0]);
                } else {
                    _boolean = this.playerCutawaysDirty[int0];
                }
            } else {
                int int2 = (int)(isoPlayer.getX() - 1.5F);
                int int3 = (int)(isoPlayer.getY() - 1.5F);
                int int4 = (int)(isoPlayer.getX() + 1.5F);
                int int5 = (int)(isoPlayer.getY() + 1.5F);

                for (int int6 = int2; int6 <= int4; int6++) {
                    for (int int7 = int3; int7 <= int5; int7++) {
                        IsoGridSquare isoGridSquare1 = this.getGridSquare(int6, int7, isoGridSquare0.getZ());
                        if (isoGridSquare1 != null) {
                            int int8 = isoGridSquare1.getRoomID();
                            if (isoGridSquare1.getCanSee(int0) && int8 != -1 && !this.tempPlayerCutawayRoomIDs.contains(int8)) {
                                this.tempCutawaySqrVector
                                    .set((float)isoGridSquare1.getX() + 0.5F - isoPlayer.getX(), (float)isoGridSquare1.getY() + 0.5F - isoPlayer.getY());
                                if (isoGridSquare0 == isoGridSquare1 || isoPlayer.getForwardDirection().dot(this.tempCutawaySqrVector) > 0.0F) {
                                    this.tempPlayerCutawayRoomIDs.add(int8);
                                }
                            }
                        }
                    }
                }

                Collections.sort(this.tempPlayerCutawayRoomIDs);
            }

            return _boolean || !this.tempPlayerCutawayRoomIDs.equals(this.tempPrevPlayerCutawayRoomIDs);
        }
    }

    private boolean IsCutawaySquare(IsoGridSquare isoGridSquare0, long _long) {
        int int0 = IsoCamera.frameState.playerIndex;
        IsoPlayer isoPlayer = IsoPlayer.players[int0];
        if (isoPlayer.current == null) {
            return false;
        } else if (isoGridSquare0 == null) {
            return false;
        } else {
            IsoGridSquare isoGridSquare1 = isoPlayer.current;
            if (isoGridSquare1.getZ() != isoGridSquare0.getZ()) {
                return false;
            } else {
                if (this.tempPlayerCutawayRoomIDs.isEmpty()) {
                    IsoGridSquare isoGridSquare2 = isoGridSquare0.nav[IsoDirections.N.index()];
                    IsoGridSquare isoGridSquare3 = isoGridSquare0.nav[IsoDirections.W.index()];
                    if (this.IsCollapsibleBuildingSquare(isoGridSquare0)) {
                        if (isoPlayer.getZ() == 0.0F) {
                            return true;
                        }

                        if (isoGridSquare0.getBuilding() != null
                            && (isoGridSquare1.getX() < isoGridSquare0.getBuilding().def.x || isoGridSquare1.getY() < isoGridSquare0.getBuilding().def.y)) {
                            return true;
                        }

                        IsoGridSquare isoGridSquare4 = isoGridSquare0;

                        for (int int1 = 0; int1 < 3; int1++) {
                            isoGridSquare4 = isoGridSquare4.nav[IsoDirections.NW.index()];
                            if (isoGridSquare4 == null) {
                                break;
                            }

                            if (isoGridSquare4.isCanSee(int0)) {
                                return true;
                            }
                        }
                    }

                    if (isoGridSquare2 != null && isoGridSquare2.getRoomID() == -1 && isoGridSquare3 != null && isoGridSquare3.getRoomID() == -1) {
                        return this.DoesSquareHaveValidCutaways(isoGridSquare1, isoGridSquare0, int0, _long);
                    }
                } else {
                    IsoGridSquare isoGridSquare5 = isoGridSquare0.nav[IsoDirections.N.index()];
                    IsoGridSquare isoGridSquare6 = isoGridSquare0.nav[IsoDirections.E.index()];
                    IsoGridSquare isoGridSquare7 = isoGridSquare0.nav[IsoDirections.S.index()];
                    IsoGridSquare isoGridSquare8 = isoGridSquare0.nav[IsoDirections.W.index()];
                    IsoGridSquare isoGridSquare9 = isoGridSquare1.nav[IsoDirections.N.index()];
                    IsoGridSquare isoGridSquare10 = isoGridSquare1.nav[IsoDirections.E.index()];
                    IsoGridSquare isoGridSquare11 = isoGridSquare1.nav[IsoDirections.S.index()];
                    IsoGridSquare isoGridSquare12 = isoGridSquare1.nav[IsoDirections.W.index()];
                    boolean boolean0 = false;
                    boolean boolean1 = false;

                    for (int int2 = 0; int2 < 8; int2++) {
                        if (isoGridSquare0.nav[int2] != null && isoGridSquare0.nav[int2].getRoomID() != isoGridSquare0.getRoomID()) {
                            boolean0 = true;
                            break;
                        }
                    }

                    if (!this.tempPlayerCutawayRoomIDs.contains(isoGridSquare0.getRoomID())) {
                        boolean1 = true;
                    }

                    if (boolean0 || boolean1 || isoGridSquare0.getWall() != null) {
                        IsoGridSquare isoGridSquare13 = isoGridSquare0;

                        for (int int3 = 0; int3 < 3; int3++) {
                            isoGridSquare13 = isoGridSquare13.nav[IsoDirections.NW.index()];
                            if (isoGridSquare13 == null) {
                                break;
                            }

                            if (isoGridSquare13.getRoomID() != -1 && this.tempPlayerCutawayRoomIDs.contains(isoGridSquare13.getRoomID())) {
                                if ((boolean0 || boolean1) && isoGridSquare13.getCanSee(int0)) {
                                    return true;
                                }

                                if (isoGridSquare0.getWall() != null && isoGridSquare13.isCouldSee(int0)) {
                                    return true;
                                }
                            }
                        }
                    }

                    if (isoGridSquare5 != null
                        && isoGridSquare8 != null
                        && (
                            isoGridSquare5.getThumpableWallOrHoppable(false) != null
                                || isoGridSquare8.getThumpableWallOrHoppable(true) != null
                                || isoGridSquare0.getThumpableWallOrHoppable(true) != null
                                || isoGridSquare0.getThumpableWallOrHoppable(false) != null
                        )) {
                        return this.DoesSquareHaveValidCutaways(isoGridSquare1, isoGridSquare0, int0, _long);
                    }

                    if (isoGridSquare1.getRoomID() == -1
                        && (
                            isoGridSquare9 != null && isoGridSquare9.getRoomID() != -1
                                || isoGridSquare10 != null && isoGridSquare10.getRoomID() != -1
                                || isoGridSquare11 != null && isoGridSquare11.getRoomID() != -1
                                || isoGridSquare12 != null && isoGridSquare12.getRoomID() != -1
                        )) {
                        int int4 = isoGridSquare1.x - isoGridSquare0.x;
                        int int5 = isoGridSquare1.y - isoGridSquare0.y;
                        if (int4 < 0 && int5 < 0) {
                            if (int4 >= -3) {
                                if (int5 >= -3) {
                                    return true;
                                }

                                if (isoGridSquare5 != null
                                    && isoGridSquare7 != null
                                    && isoGridSquare0.getWall(false) != null
                                    && isoGridSquare5.getWall(false) != null
                                    && isoGridSquare7.getWall(false) != null
                                    && isoGridSquare7.getPlayerCutawayFlag(int0, _long)) {
                                    return true;
                                }
                            } else if (isoGridSquare6 != null && isoGridSquare8 != null) {
                                if (isoGridSquare0.getWall(true) != null
                                    && isoGridSquare8.getWall(true) != null
                                    && isoGridSquare6.getWall(true) != null
                                    && isoGridSquare6.getPlayerCutawayFlag(int0, _long)) {
                                    return true;
                                }

                                if (isoGridSquare0.getWall(true) != null
                                    && isoGridSquare8.getWall(true) != null
                                    && isoGridSquare6.getWall(true) != null
                                    && isoGridSquare6.getPlayerCutawayFlag(int0, _long)) {
                                    return true;
                                }
                            }
                        }
                    }
                }

                return false;
            }
        }
    }

    private boolean DoesSquareHaveValidCutaways(IsoGridSquare isoGridSquare6, IsoGridSquare isoGridSquare1, int int1, long _long) {
        IsoGridSquare isoGridSquare0 = isoGridSquare1.nav[IsoDirections.N.index()];
        IsoGridSquare isoGridSquare2 = isoGridSquare1.nav[IsoDirections.E.index()];
        IsoGridSquare isoGridSquare3 = isoGridSquare1.nav[IsoDirections.S.index()];
        IsoGridSquare isoGridSquare4 = isoGridSquare1.nav[IsoDirections.W.index()];
        IsoObject isoObject0 = isoGridSquare1.getWall(true);
        IsoObject isoObject1 = isoGridSquare1.getWall(false);
        IsoObject isoObject2 = null;
        IsoObject isoObject3 = null;
        if (isoGridSquare0 != null
            && isoGridSquare0.nav[IsoDirections.W.index()] != null
            && isoGridSquare0.nav[IsoDirections.W.index()].getRoomID() == isoGridSquare0.getRoomID()) {
            isoObject3 = isoGridSquare0.getWall(false);
        }

        if (isoGridSquare4 != null
            && isoGridSquare4.nav[IsoDirections.N.index()] != null
            && isoGridSquare4.nav[IsoDirections.N.index()].getRoomID() == isoGridSquare4.getRoomID()) {
            isoObject2 = isoGridSquare4.getWall(true);
        }

        if (isoObject1 != null || isoObject0 != null || isoObject3 != null || isoObject2 != null) {
            IsoGridSquare isoGridSquare5 = isoGridSquare1.nav[IsoDirections.NW.index()];

            for (int int0 = 0; int0 < 2 && isoGridSquare5 != null && isoGridSquare5.getRoomID() == isoGridSquare6.getRoomID(); int0++) {
                IsoGridSquare isoGridSquare7 = isoGridSquare5.nav[IsoDirections.S.index()];
                IsoGridSquare isoGridSquare8 = isoGridSquare5.nav[IsoDirections.E.index()];
                if (isoGridSquare7 != null && isoGridSquare7.getBuilding() != null || isoGridSquare8 != null && isoGridSquare8.getBuilding() != null) {
                    break;
                }

                if (isoGridSquare5.isCanSee(int1) && isoGridSquare5.isCouldSee(int1) && isoGridSquare5.DistTo(isoGridSquare6) <= (float)(6 - (int0 + 1))) {
                    return true;
                }

                if (isoGridSquare5.getBuilding() == null) {
                    isoGridSquare5 = isoGridSquare5.nav[IsoDirections.NW.index()];
                }
            }
        }

        int int2 = isoGridSquare6.x - isoGridSquare1.x;
        int int3 = isoGridSquare6.y - isoGridSquare1.y;
        if ((isoObject0 == null || !isoObject0.sprite.name.contains("fencing")) && (isoObject1 == null || !isoObject1.sprite.name.contains("fencing"))) {
            if (isoGridSquare1.DistTo(isoGridSquare6) <= 6.0F
                && isoGridSquare1.nav[IsoDirections.NW.index()] != null
                && isoGridSquare1.nav[IsoDirections.NW.index()].getRoomID() == isoGridSquare1.getRoomID()
                && (isoGridSquare1.getWall(true) == null || isoGridSquare1.getWall(true) == isoObject0)
                && (isoGridSquare1.getWall(false) == null || isoGridSquare1.getWall(false) == isoObject1)) {
                if (isoGridSquare3 != null && isoGridSquare0 != null && int3 != 0) {
                    if (int3 > 0
                        && isoObject1 != null
                        && isoGridSquare3.getWall(false) != null
                        && isoGridSquare0.getWall(false) != null
                        && isoGridSquare3.getPlayerCutawayFlag(int1, _long)) {
                        return true;
                    }

                    if (int3 < 0 && isoObject1 != null && isoGridSquare0.getWall(false) != null && isoGridSquare0.getPlayerCutawayFlag(int1, _long)) {
                        return true;
                    }
                }

                if (isoGridSquare2 != null && isoGridSquare4 != null && int2 != 0) {
                    if (int2 > 0
                        && isoObject0 != null
                        && isoGridSquare2.getWall(true) != null
                        && isoGridSquare4.getWall(true) != null
                        && isoGridSquare2.getPlayerCutawayFlag(int1, _long)) {
                        return true;
                    }

                    if (int2 < 0 && isoObject0 != null && isoGridSquare4.getWall(true) != null && isoGridSquare4.getPlayerCutawayFlag(int1, _long)) {
                        return true;
                    }
                }
            }
        } else {
            if (isoObject0 != null && isoObject2 != null && int3 >= -6 && int3 < 0) {
                return true;
            }

            if (isoObject1 != null && isoObject3 != null && int2 >= -6 && int2 < 0) {
                return true;
            }
        }

        if (isoGridSquare1 == isoGridSquare6
            && isoGridSquare1.nav[IsoDirections.NW.index()] != null
            && isoGridSquare1.nav[IsoDirections.NW.index()].getRoomID() == isoGridSquare1.getRoomID()) {
            if (isoObject0 != null
                && isoGridSquare0 != null
                && isoGridSquare0.getWall(false) == null
                && isoGridSquare0.isCanSee(int1)
                && isoGridSquare0.isCouldSee(int1)) {
                return true;
            }

            if (isoObject1 != null
                && isoGridSquare4 != null
                && isoGridSquare4.getWall(true) != null
                && isoGridSquare4.isCanSee(int1)
                && isoGridSquare4.isCouldSee(int1)) {
                return true;
            }
        }

        return isoGridSquare0 != null
                && isoGridSquare4 != null
                && int2 != 0
                && int3 != 0
                && isoObject3 != null
                && isoObject2 != null
                && isoGridSquare0.getPlayerCutawayFlag(int1, _long)
                && isoGridSquare4.getPlayerCutawayFlag(int1, _long)
            ? true
            : int2 < 0
                && int2 >= -6
                && int3 < 0
                && int3 >= -6
                && (isoObject1 != null && isoGridSquare1.getWall(true) == null || isoObject0 != null && isoGridSquare1.getWall(false) == null);
    }

    private boolean IsCollapsibleBuildingSquare(IsoGridSquare isoGridSquare) {
        if (isoGridSquare.getProperties().Is(IsoFlagType.forceRender)) {
            return false;
        } else {
            for (int int0 = 0; int0 < 4; int0++) {
                short _short = 500;

                for (int int1 = 0; int1 < _short && this.playerOccluderBuildingsArr[int0] != null; int1++) {
                    IsoBuilding isoBuilding0 = this.playerOccluderBuildingsArr[int0][int1];
                    if (isoBuilding0 == null) {
                        break;
                    }

                    BuildingDef buildingDef0 = isoBuilding0.getDef();
                    if (this.collapsibleBuildingSquareAlgorithm(buildingDef0, isoGridSquare, IsoPlayer.players[int0].getSquare())) {
                        return true;
                    }

                    if (isoGridSquare.getY() - buildingDef0.getY2() == 1 && isoGridSquare.getWall(true) != null) {
                        return true;
                    }

                    if (isoGridSquare.getX() - buildingDef0.getX2() == 1 && isoGridSquare.getWall(false) != null) {
                        return true;
                    }
                }
            }

            int int2 = IsoCamera.frameState.playerIndex;
            IsoPlayer isoPlayer = IsoPlayer.players[int2];
            if (isoPlayer.getVehicle() != null) {
                return false;
            } else {
                for (int int3 = 0; int3 < 500 && this.zombieOccluderBuildingsArr[int2] != null; int3++) {
                    IsoBuilding isoBuilding1 = this.zombieOccluderBuildingsArr[int2][int3];
                    if (isoBuilding1 == null) {
                        break;
                    }

                    BuildingDef buildingDef1 = isoBuilding1.getDef();
                    if (this.collapsibleBuildingSquareAlgorithm(buildingDef1, isoGridSquare, isoPlayer.getSquare())) {
                        return true;
                    }
                }

                for (int int4 = 0; int4 < 500 && this.otherOccluderBuildingsArr[int2] != null; int4++) {
                    IsoBuilding isoBuilding2 = this.otherOccluderBuildingsArr[int2][int4];
                    if (isoBuilding2 == null) {
                        break;
                    }

                    BuildingDef buildingDef2 = isoBuilding2.getDef();
                    if (this.collapsibleBuildingSquareAlgorithm(buildingDef2, isoGridSquare, isoPlayer.getSquare())) {
                        return true;
                    }
                }

                return false;
            }
        }
    }

    private boolean collapsibleBuildingSquareAlgorithm(BuildingDef buildingDef, IsoGridSquare isoGridSquare2, IsoGridSquare isoGridSquare0) {
        int int0 = buildingDef.getX();
        int int1 = buildingDef.getY();
        int int2 = buildingDef.getX2() - int0;
        int int3 = buildingDef.getY2() - int1;
        this.buildingRectTemp.setBounds(int0, int1, int2, int3);
        if (isoGridSquare0.getRoomID() == -1 && this.buildingRectTemp.contains(isoGridSquare0.getX(), isoGridSquare0.getY())) {
            this.buildingRectTemp.setBounds(int0 - 1, int1 - 1, int2 + 2, int3 + 2);
            IsoGridSquare isoGridSquare1 = isoGridSquare2.nav[IsoDirections.N.index()];
            IsoGridSquare isoGridSquare3 = isoGridSquare2.nav[IsoDirections.W.index()];
            IsoGridSquare isoGridSquare4 = isoGridSquare2.nav[IsoDirections.NW.index()];
            if (isoGridSquare4 != null && isoGridSquare1 != null && isoGridSquare3 != null) {
                boolean boolean0 = isoGridSquare2.getRoomID() == -1;
                boolean boolean1 = isoGridSquare1.getRoomID() == -1;
                boolean boolean2 = isoGridSquare3.getRoomID() == -1;
                boolean boolean3 = isoGridSquare4.getRoomID() == -1;
                boolean boolean4 = isoGridSquare0.getY() < isoGridSquare2.getY();
                boolean boolean5 = isoGridSquare0.getX() < isoGridSquare2.getX();
                return this.buildingRectTemp.contains(isoGridSquare2.getX(), isoGridSquare2.getY())
                    && (
                        isoGridSquare0.getZ() < isoGridSquare2.getZ()
                            || boolean0 && (!boolean1 && boolean4 || !boolean2 && boolean5)
                            || boolean0 && boolean1 && boolean2 && !boolean3
                            || !boolean0 && (boolean3 || boolean1 == boolean2 || boolean1 && boolean5 || boolean2 && boolean4)
                    );
            } else {
                return false;
            }
        } else {
            this.buildingRectTemp.setBounds(int0 - 1, int1 - 1, int2 + 2, int3 + 2);
            return this.buildingRectTemp.contains(isoGridSquare2.getX(), isoGridSquare2.getY());
        }
    }

    private boolean IsDissolvedSquare(IsoGridSquare isoGridSquare1, int int0) {
        IsoPlayer isoPlayer = IsoPlayer.players[int0];
        if (isoPlayer.current == null) {
            return false;
        } else {
            IsoGridSquare isoGridSquare0 = isoPlayer.current;
            if (isoGridSquare0.getZ() >= isoGridSquare1.getZ()) {
                return false;
            } else if (!PerformanceSettings.NewRoofHiding) {
                return this.bHideFloors[int0] && isoGridSquare1.getZ() >= this.maxZ;
            } else {
                if (isoGridSquare1.getZ() > this.hidesOrphanStructuresAbove) {
                    IsoBuilding isoBuilding = isoGridSquare1.getBuilding();
                    if (isoBuilding == null) {
                        isoBuilding = isoGridSquare1.roofHideBuilding;
                    }

                    for (int int1 = isoGridSquare1.getZ() - 1; int1 >= 0 && isoBuilding == null; int1--) {
                        IsoGridSquare isoGridSquare2 = this.getGridSquare(isoGridSquare1.x, isoGridSquare1.y, int1);
                        if (isoGridSquare2 != null) {
                            isoBuilding = isoGridSquare2.getBuilding();
                            if (isoBuilding == null) {
                                isoBuilding = isoGridSquare2.roofHideBuilding;
                            }
                        }
                    }

                    if (isoBuilding == null) {
                        if (isoGridSquare1.isSolidFloor()) {
                            return true;
                        }

                        IsoGridSquare isoGridSquare3 = isoGridSquare1.nav[IsoDirections.N.index()];
                        if (isoGridSquare3 != null && isoGridSquare3.getBuilding() == null) {
                            if (isoGridSquare3.getPlayerBuiltFloor() != null) {
                                return true;
                            }

                            if (isoGridSquare3.HasStairsBelow()) {
                                return true;
                            }
                        }

                        IsoGridSquare isoGridSquare4 = isoGridSquare1.nav[IsoDirections.W.index()];
                        if (isoGridSquare4 != null && isoGridSquare4.getBuilding() == null) {
                            if (isoGridSquare4.getPlayerBuiltFloor() != null) {
                                return true;
                            }

                            if (isoGridSquare4.HasStairsBelow()) {
                                return true;
                            }
                        }

                        if (isoGridSquare1.Is(IsoFlagType.WallSE)) {
                            IsoGridSquare isoGridSquare5 = isoGridSquare1.nav[IsoDirections.NW.index()];
                            if (isoGridSquare5 != null && isoGridSquare5.getBuilding() == null) {
                                if (isoGridSquare5.getPlayerBuiltFloor() != null) {
                                    return true;
                                }

                                if (isoGridSquare5.HasStairsBelow()) {
                                    return true;
                                }
                            }
                        }
                    }
                }

                return this.IsCollapsibleBuildingSquare(isoGridSquare1);
            }
        }
    }

    private int GetBuildingHeightAt(IsoBuilding isoBuilding, int int2, int int3, int int1) {
        for (int int0 = MaxHeight; int0 > int1; int0--) {
            IsoGridSquare isoGridSquare = this.getGridSquare(int2, int3, int0);
            if (isoGridSquare != null && isoGridSquare.getBuilding() == isoBuilding) {
                return int0;
            }
        }

        return int1;
    }

    private void updateSnow(int _int) {
        if (this.snowGridCur == null) {
            this.snowGridCur = new IsoCell.SnowGrid(_int);
            this.snowGridPrev = new IsoCell.SnowGrid(0);
        } else {
            if (_int != this.snowGridCur.frac) {
                this.snowGridPrev.init(this.snowGridCur.frac);
                this.snowGridCur.init(_int);
                this.snowFadeTime = System.currentTimeMillis();
                DebugLog.log("snow from " + this.snowGridPrev.frac + " to " + this.snowGridCur.frac);
            }
        }
    }

    public void setSnowTarget(int target) {
        if (!zombie.SandboxOptions.instance.EnableSnowOnGround.getValue()) {
            target = 0;
        }

        this.snowFracTarget = target;
    }

    public boolean gridSquareIsSnow(int x, int y, int z) {
        IsoGridSquare isoGridSquare = this.getGridSquare(x, y, z);
        if (isoGridSquare != null) {
            if (!isoGridSquare.getProperties().Is(IsoFlagType.solidfloor)) {
                return false;
            } else if (isoGridSquare.getProperties().Is(IsoFlagType.water)) {
                return false;
            } else if (isoGridSquare.getProperties().Is(IsoFlagType.exterior) && isoGridSquare.room == null && !isoGridSquare.isInARoom()) {
                int int0 = isoGridSquare.getX() % this.snowGridCur.w;
                int int1 = isoGridSquare.getY() % this.snowGridCur.h;
                return this.snowGridCur.check(int0, int1);
            } else {
                return false;
            }
        } else {
            return false;
        }
    }

    private void RenderSnow(int int6) {
        if (DebugOptions.instance.Weather.Snow.getValue()) {
            this.updateSnow(this.snowFracTarget);
            IsoCell.SnowGrid snowGrid0 = this.snowGridCur;
            if (snowGrid0 != null) {
                IsoCell.SnowGrid snowGrid1 = this.snowGridPrev;
                if (snowGrid0.frac > 0 || snowGrid1.frac > 0) {
                    float float0 = 1.0F;
                    float float1 = 0.0F;
                    long long0 = System.currentTimeMillis();
                    long long1 = long0 - this.snowFadeTime;
                    if ((float)long1 < this.snowTransitionTime) {
                        float float2 = (float)long1 / this.snowTransitionTime;
                        float0 = float2;
                        float1 = 1.0F - float2;
                    }

                    Shader shader = null;
                    if (DebugOptions.instance.Terrain.RenderTiles.UseShaders.getValue()) {
                        shader = m_floorRenderShader;
                    }

                    FloorShaperAttachedSprites.instance.setShore(false);
                    FloorShaperDiamond.instance.setShore(false);
                    zombie.IndieGL.StartShader(shader, IsoCamera.frameState.playerIndex);
                    int int0 = (int)IsoCamera.frameState.OffX;
                    int int1 = (int)IsoCamera.frameState.OffY;

                    for (int int2 = 0; int2 < SolidFloor.size(); int2++) {
                        IsoGridSquare isoGridSquare = (IsoGridSquare)SolidFloor.get(int2);
                        if (isoGridSquare.room == null
                            && isoGridSquare.getProperties().Is(IsoFlagType.exterior)
                            && isoGridSquare.getProperties().Is(IsoFlagType.solidfloor)) {
                            int int3;
                            if (isoGridSquare.getProperties().Is(IsoFlagType.water)) {
                                int3 = getShoreInt(isoGridSquare);
                                if (int3 == 0) {
                                    continue;
                                }
                            } else {
                                int3 = 0;
                            }

                            int int4 = isoGridSquare.getX() % snowGrid0.w;
                            int int5 = isoGridSquare.getY() % snowGrid0.h;
                            float float3 = IsoUtils.XToScreen((float)isoGridSquare.getX(), (float)isoGridSquare.getY(), (float)int6, 0);
                            float float4 = IsoUtils.YToScreen((float)isoGridSquare.getX(), (float)isoGridSquare.getY(), (float)int6, 0);
                            float3 -= (float)int0;
                            float4 -= (float)int1;
                            float float5 = (float)(32 * Core.TileScale);
                            float float6 = (float)(96 * Core.TileScale);
                            float3 -= float5;
                            float4 -= float6;
                            int int7 = IsoCamera.frameState.playerIndex;
                            int int8 = isoGridSquare.getVertLight(0, int7);
                            int int9 = isoGridSquare.getVertLight(1, int7);
                            int int10 = isoGridSquare.getVertLight(2, int7);
                            int int11 = isoGridSquare.getVertLight(3, int7);
                            if (DebugOptions.instance.Terrain.RenderTiles.IsoGridSquare.Floor.LightingDebug.getValue()) {
                                int8 = -65536;
                                int9 = -65536;
                                int10 = -16776961;
                                int11 = -16776961;
                            }

                            FloorShaperAttachedSprites.instance.setVertColors(int8, int9, int10, int11);
                            FloorShaperDiamond.instance.setVertColors(int8, int9, int10, int11);

                            for (int int12 = 0; int12 < 2; int12++) {
                                if (float1 > float0) {
                                    this.renderSnowTileGeneral(snowGrid0, float0, isoGridSquare, int3, int4, int5, (int)float3, (int)float4, int12);
                                    this.renderSnowTileGeneral(snowGrid1, float1, isoGridSquare, int3, int4, int5, (int)float3, (int)float4, int12);
                                } else {
                                    this.renderSnowTileGeneral(snowGrid1, float1, isoGridSquare, int3, int4, int5, (int)float3, (int)float4, int12);
                                    this.renderSnowTileGeneral(snowGrid0, float0, isoGridSquare, int3, int4, int5, (int)float3, (int)float4, int12);
                                }
                            }
                        }
                    }

                    zombie.IndieGL.StartShader(null);
                }
            }
        }
    }

    private void renderSnowTileGeneral(
        IsoCell.SnowGrid snowGrid, float _float, IsoGridSquare isoGridSquare, int int3, int int2, int int1, int int4, int int5, int int0
    ) {
        if (!(_float <= 0.0F)) {
            Texture texture = snowGrid.grid[int2][int1][int0];
            if (texture != null) {
                if (int0 == 0) {
                    this.renderSnowTile(snowGrid, int2, int1, int0, isoGridSquare, int3, texture, int4, int5, _float);
                } else if (int3 == 0) {
                    byte _byte = snowGrid.gridType[int2][int1][int0];
                    this.renderSnowTileBase(texture, int4, int5, _float, _byte < this.m_snowFirstNonSquare);
                }
            }
        }
    }

    private void renderSnowTileBase(Texture texture, int int1, int int0, float _float, boolean _boolean) {
        Object object = _boolean ? FloorShaperDiamond.instance : FloorShaperAttachedSprites.instance;
        ((FloorShaper)object).setAlpha4(_float);
        texture.render((float)int1, (float)int0, (float)texture.getWidth(), (float)texture.getHeight(), 1.0F, 1.0F, 1.0F, _float, (Consumer<TextureDraw>)object);
    }

    private void renderSnowTile(
        IsoCell.SnowGrid snowGrid, int int3, int int2, int int1, IsoGridSquare isoGridSquare, int int0, Texture texture, int int4, int int5, float _float
    ) {
        if (int0 == 0) {
            byte _byte = snowGrid.gridType[int3][int2][int1];
            this.renderSnowTileBase(texture, int4, int5, _float, _byte < this.m_snowFirstNonSquare);
        } else {
            int int6 = 0;
            boolean boolean0 = snowGrid.check(int3, int2);
            boolean boolean1 = (int0 & 1) == 1 && (boolean0 || snowGrid.check(int3, int2 - 1));
            boolean boolean2 = (int0 & 2) == 2 && (boolean0 || snowGrid.check(int3 + 1, int2));
            boolean boolean3 = (int0 & 4) == 4 && (boolean0 || snowGrid.check(int3, int2 + 1));
            boolean boolean4 = (int0 & 8) == 8 && (boolean0 || snowGrid.check(int3 - 1, int2));
            if (boolean1) {
                int6++;
            }

            if (boolean3) {
                int6++;
            }

            if (boolean2) {
                int6++;
            }

            if (boolean4) {
                int6++;
            }

            IsoCell.SnowGridTiles snowGridTiles0 = null;
            IsoCell.SnowGridTiles snowGridTiles1 = null;
            boolean boolean5 = false;
            if (int6 != 0) {
                if (int6 == 1) {
                    if (boolean1) {
                        snowGridTiles0 = this.snowGridTiles_Strip[0];
                    } else if (boolean3) {
                        snowGridTiles0 = this.snowGridTiles_Strip[1];
                    } else if (boolean2) {
                        snowGridTiles0 = this.snowGridTiles_Strip[3];
                    } else if (boolean4) {
                        snowGridTiles0 = this.snowGridTiles_Strip[2];
                    }
                } else if (int6 == 2) {
                    if (boolean1 && boolean3) {
                        snowGridTiles0 = this.snowGridTiles_Strip[0];
                        snowGridTiles1 = this.snowGridTiles_Strip[1];
                    } else if (boolean2 && boolean4) {
                        snowGridTiles0 = this.snowGridTiles_Strip[2];
                        snowGridTiles1 = this.snowGridTiles_Strip[3];
                    } else if (boolean1) {
                        snowGridTiles0 = this.snowGridTiles_Edge[boolean4 ? 0 : 3];
                    } else if (boolean3) {
                        snowGridTiles0 = this.snowGridTiles_Edge[boolean4 ? 2 : 1];
                    } else if (boolean4) {
                        snowGridTiles0 = this.snowGridTiles_Edge[boolean1 ? 0 : 2];
                    } else if (boolean2) {
                        snowGridTiles0 = this.snowGridTiles_Edge[boolean1 ? 3 : 1];
                    }
                } else if (int6 == 3) {
                    if (!boolean1) {
                        snowGridTiles0 = this.snowGridTiles_Cove[1];
                    } else if (!boolean3) {
                        snowGridTiles0 = this.snowGridTiles_Cove[0];
                    } else if (!boolean2) {
                        snowGridTiles0 = this.snowGridTiles_Cove[2];
                    } else if (!boolean4) {
                        snowGridTiles0 = this.snowGridTiles_Cove[3];
                    }

                    boolean5 = true;
                } else if (int6 == 4) {
                    snowGridTiles0 = this.snowGridTiles_Enclosed;
                    boolean5 = true;
                }

                if (snowGridTiles0 != null) {
                    int int7 = (isoGridSquare.getX() + isoGridSquare.getY()) % snowGridTiles0.size();
                    texture = snowGridTiles0.get(int7);
                    if (texture != null) {
                        this.renderSnowTileBase(texture, int4, int5, _float, boolean5);
                    }

                    if (snowGridTiles1 != null) {
                        texture = snowGridTiles1.get(int7);
                        if (texture != null) {
                            this.renderSnowTileBase(texture, int4, int5, _float, false);
                        }
                    }
                }
            }
        }
    }

    private static int getShoreInt(IsoGridSquare isoGridSquare) {
        byte _byte = 0;
        if (isSnowShore(isoGridSquare, 0, -1)) {
            _byte |= 1;
        }

        if (isSnowShore(isoGridSquare, 1, 0)) {
            _byte |= 2;
        }

        if (isSnowShore(isoGridSquare, 0, 1)) {
            _byte |= 4;
        }

        if (isSnowShore(isoGridSquare, -1, 0)) {
            _byte |= 8;
        }

        return _byte;
    }

    private static boolean isSnowShore(IsoGridSquare isoGridSquare1, int int1, int int0) {
        IsoGridSquare isoGridSquare0 = IsoWorld.instance.getCell().getGridSquare(isoGridSquare1.getX() + int1, isoGridSquare1.getY() + int0, 0);
        return isoGridSquare0 != null && !isoGridSquare0.getProperties().Is(IsoFlagType.water);
    }

    public IsoBuilding getClosestBuildingExcept(IsoGameCharacter chr, IsoRoom except) {
        IsoBuilding isoBuilding0 = null;
        float float0 = 1000000.0F;

        for (int int0 = 0; int0 < this.BuildingList.size(); int0++) {
            IsoBuilding isoBuilding1 = (IsoBuilding)this.BuildingList.get(int0);

            for (int int1 = 0; int1 < isoBuilding1.Exits.size(); int1++) {
                float float1 = chr.DistTo(((IsoRoomExit)isoBuilding1.Exits.get(int1)).x, ((IsoRoomExit)isoBuilding1.Exits.get(int1)).y);
                if (float1 < float0 && (except == null || except.building != isoBuilding1)) {
                    isoBuilding0 = isoBuilding1;
                    float0 = float1;
                }
            }
        }

        return isoBuilding0;
    }

    public int getDangerScore(int x, int y) {
        return x >= 0 && y >= 0 && x < this.width && y < this.height ? this.DangerScore.getValue(x, y) : 1000000;
    }

    private void ObjectDeletionAddition() {
        for (int int0 = 0; int0 < this.removeList.size(); int0++) {
            IsoMovingObject isoMovingObject0 = (IsoMovingObject)this.removeList.get(int0);
            if (isoMovingObject0 instanceof IsoZombie) {
                zombie.VirtualZombieManager.instance.RemoveZombie((IsoZombie)isoMovingObject0);
            }

            if (!(isoMovingObject0 instanceof IsoPlayer) || ((IsoPlayer)isoMovingObject0).isDead()) {
                zombie.MovingObjectUpdateScheduler.instance.removeObject(isoMovingObject0);
                this.ObjectList.remove(isoMovingObject0);
                if (isoMovingObject0.getCurrentSquare() != null) {
                    isoMovingObject0.getCurrentSquare().getMovingObjects().remove(isoMovingObject0);
                }

                if (isoMovingObject0.getLastSquare() != null) {
                    isoMovingObject0.getLastSquare().getMovingObjects().remove(isoMovingObject0);
                }
            }
        }

        this.removeList.clear();

        for (int int1 = 0; int1 < this.addList.size(); int1++) {
            IsoMovingObject isoMovingObject1 = (IsoMovingObject)this.addList.get(int1);
            this.ObjectList.add(isoMovingObject1);
        }

        this.addList.clear();

        for (int int2 = 0; int2 < this.addVehicles.size(); int2++) {
            BaseVehicle baseVehicle = (BaseVehicle)this.addVehicles.get(int2);
            if (!this.ObjectList.contains(baseVehicle)) {
                this.ObjectList.add(baseVehicle);
            }

            if (!this.vehicles.contains(baseVehicle)) {
                this.vehicles.add(baseVehicle);
            }
        }

        this.addVehicles.clear();
    }

    private void ProcessItems(Iterator<InventoryItem> var1) {
        int int0 = this.ProcessItems.size();

        for (int int1 = 0; int1 < int0; int1++) {
            InventoryItem inventoryItem = (InventoryItem)this.ProcessItems.get(int1);
            inventoryItem.update();
            if (inventoryItem.finishupdate()) {
                this.ProcessItemsRemove.add(inventoryItem);
            }
        }

        int0 = this.ProcessWorldItems.size();

        for (int int2 = 0; int2 < int0; int2++) {
            IsoWorldInventoryObject isoWorldInventoryObject = (IsoWorldInventoryObject)this.ProcessWorldItems.get(int2);
            isoWorldInventoryObject.update();
            if (isoWorldInventoryObject.finishupdate()) {
                this.ProcessWorldItemsRemove.add(isoWorldInventoryObject);
            }
        }
    }

    private void ProcessIsoObject() {
        this.ProcessIsoObject.removeAll(this.ProcessIsoObjectRemove);
        this.ProcessIsoObjectRemove.clear();
        int int0 = this.ProcessIsoObject.size();

        for (int int1 = 0; int1 < int0; int1++) {
            IsoObject isoObject = (IsoObject)this.ProcessIsoObject.get(int1);
            if (isoObject != null) {
                isoObject.update();
                if (int0 > this.ProcessIsoObject.size()) {
                    int1--;
                    int0--;
                }
            }
        }
    }

    private void ProcessObjects(Iterator<IsoMovingObject> var1) {
        zombie.MovingObjectUpdateScheduler.instance.update();

        for (int _int = 0; _int < this.ZombieList.size(); _int++) {
            IsoZombie isoZombie = (IsoZombie)this.ZombieList.get(_int);
            isoZombie.updateVocalProperties();
        }
    }

    private void ProcessRemoveItems(Iterator<InventoryItem> var1) {
        this.ProcessItems.removeAll(this.ProcessItemsRemove);
        this.ProcessWorldItems.removeAll(this.ProcessWorldItemsRemove);
        this.ProcessItemsRemove.clear();
        this.ProcessWorldItemsRemove.clear();
    }

    private void ProcessStaticUpdaters() {
        int int0 = this.StaticUpdaterObjectList.size();

        for (int int1 = 0; int1 < int0; int1++) {
            try {
                ((IsoObject)this.StaticUpdaterObjectList.get(int1)).update();
            } catch (Exception exception) {
                Logger.getLogger(zombie.GameWindow.class.getName()).log(Level.SEVERE, null, exception);
            }

            if (int0 > this.StaticUpdaterObjectList.size()) {
                int1--;
                int0--;
            }
        }
    }

    public void addToProcessIsoObject(IsoObject object) {
        if (object != null) {
            this.ProcessIsoObjectRemove.remove(object);
            if (!this.ProcessIsoObject.contains(object)) {
                this.ProcessIsoObject.add(object);
            }
        }
    }

    public void addToProcessIsoObjectRemove(IsoObject object) {
        if (object != null) {
            if (this.ProcessIsoObject.contains(object)) {
                if (!this.ProcessIsoObjectRemove.contains(object)) {
                    this.ProcessIsoObjectRemove.add(object);
                }
            }
        }
    }

    public void addToStaticUpdaterObjectList(IsoObject object) {
        if (object != null) {
            if (!this.StaticUpdaterObjectList.contains(object)) {
                this.StaticUpdaterObjectList.add(object);
            }
        }
    }

    public void addToProcessItems(InventoryItem item) {
        if (item != null) {
            this.ProcessItemsRemove.remove(item);
            if (!this.ProcessItems.contains(item)) {
                this.ProcessItems.add(item);
            }
        }
    }

    public void addToProcessItems(ArrayList<InventoryItem> items) {
        if (items != null) {
            for (int _int = 0; _int < items.size(); _int++) {
                InventoryItem inventoryItem = (InventoryItem)items.get(_int);
                if (inventoryItem != null) {
                    this.ProcessItemsRemove.remove(inventoryItem);
                    if (!this.ProcessItems.contains(inventoryItem)) {
                        this.ProcessItems.add(inventoryItem);
                    }
                }
            }
        }
    }

    public void addToProcessItemsRemove(InventoryItem item) {
        if (item != null) {
            if (!this.ProcessItemsRemove.contains(item)) {
                this.ProcessItemsRemove.add(item);
            }
        }
    }

    public void addToProcessItemsRemove(ArrayList<InventoryItem> items) {
        if (items != null) {
            for (int _int = 0; _int < items.size(); _int++) {
                InventoryItem inventoryItem = (InventoryItem)items.get(_int);
                if (inventoryItem != null && !this.ProcessItemsRemove.contains(inventoryItem)) {
                    this.ProcessItemsRemove.add(inventoryItem);
                }
            }
        }
    }

    public void addToProcessWorldItems(IsoWorldInventoryObject worldItem) {
        if (worldItem != null) {
            this.ProcessWorldItemsRemove.remove(worldItem);
            if (!this.ProcessWorldItems.contains(worldItem)) {
                this.ProcessWorldItems.add(worldItem);
            }
        }
    }

    public void addToProcessWorldItemsRemove(IsoWorldInventoryObject worldItem) {
        if (worldItem != null) {
            if (!this.ProcessWorldItemsRemove.contains(worldItem)) {
                this.ProcessWorldItemsRemove.add(worldItem);
            }
        }
    }

    public IsoSurvivor getNetworkPlayer(int RemoteID) {
        int int0 = this.RemoteSurvivorList.size();

        for (int int1 = 0; int1 < int0; int1++) {
            if (((IsoGameCharacter)this.RemoteSurvivorList.get(int1)).getRemoteID() == RemoteID) {
                return (IsoSurvivor)this.RemoteSurvivorList.get(int1);
            }
        }

        return null;
    }

    IsoGridSquare ConnectNewSquare(IsoGridSquare isoGridSquare, boolean var2, boolean var3) {
        int int0 = isoGridSquare.getX();
        int int1 = isoGridSquare.getY();
        int int2 = isoGridSquare.getZ();
        this.setCacheGridSquare(int0, int1, int2, isoGridSquare);
        this.DoGridNav(isoGridSquare, IsoGridSquare.cellGetSquare);
        return isoGridSquare;
    }

    public void DoGridNav(IsoGridSquare newSquare, IsoGridSquare.GetSquare getter) {
        int int0 = newSquare.getX();
        int int1 = newSquare.getY();
        int int2 = newSquare.getZ();
        newSquare.nav[IsoDirections.N.index()] = getter.getGridSquare(int0, int1 - 1, int2);
        newSquare.nav[IsoDirections.NW.index()] = getter.getGridSquare(int0 - 1, int1 - 1, int2);
        newSquare.nav[IsoDirections.W.index()] = getter.getGridSquare(int0 - 1, int1, int2);
        newSquare.nav[IsoDirections.SW.index()] = getter.getGridSquare(int0 - 1, int1 + 1, int2);
        newSquare.nav[IsoDirections.S.index()] = getter.getGridSquare(int0, int1 + 1, int2);
        newSquare.nav[IsoDirections.SE.index()] = getter.getGridSquare(int0 + 1, int1 + 1, int2);
        newSquare.nav[IsoDirections.E.index()] = getter.getGridSquare(int0 + 1, int1, int2);
        newSquare.nav[IsoDirections.NE.index()] = getter.getGridSquare(int0 + 1, int1 - 1, int2);
        if (newSquare.nav[IsoDirections.N.index()] != null) {
            newSquare.nav[IsoDirections.N.index()].nav[IsoDirections.S.index()] = newSquare;
        }

        if (newSquare.nav[IsoDirections.NW.index()] != null) {
            newSquare.nav[IsoDirections.NW.index()].nav[IsoDirections.SE.index()] = newSquare;
        }

        if (newSquare.nav[IsoDirections.W.index()] != null) {
            newSquare.nav[IsoDirections.W.index()].nav[IsoDirections.E.index()] = newSquare;
        }

        if (newSquare.nav[IsoDirections.SW.index()] != null) {
            newSquare.nav[IsoDirections.SW.index()].nav[IsoDirections.NE.index()] = newSquare;
        }

        if (newSquare.nav[IsoDirections.S.index()] != null) {
            newSquare.nav[IsoDirections.S.index()].nav[IsoDirections.N.index()] = newSquare;
        }

        if (newSquare.nav[IsoDirections.SE.index()] != null) {
            newSquare.nav[IsoDirections.SE.index()].nav[IsoDirections.NW.index()] = newSquare;
        }

        if (newSquare.nav[IsoDirections.E.index()] != null) {
            newSquare.nav[IsoDirections.E.index()].nav[IsoDirections.W.index()] = newSquare;
        }

        if (newSquare.nav[IsoDirections.NE.index()] != null) {
            newSquare.nav[IsoDirections.NE.index()].nav[IsoDirections.SW.index()] = newSquare;
        }
    }

    public IsoGridSquare ConnectNewSquare(IsoGridSquare newSquare, boolean bDoSurrounds) {
        for (int _int = 0; _int < IsoPlayer.numPlayers; _int++) {
            if (!this.ChunkMap[_int].ignore) {
                this.ChunkMap[_int].setGridSquare(newSquare, newSquare.getX(), newSquare.getY(), newSquare.getZ());
            }
        }

        return this.ConnectNewSquare(newSquare, bDoSurrounds, false);
    }

    public void PlaceLot(String filename, int sx, int sy, int sz, boolean bClearExisting) {
    }

    public void PlaceLot(IsoLot lot, int sx, int sy, int sz, boolean bClearExisting) {
        int int0 = Math.min(sz + lot.info.levels, sz + 8);

        for (int int1 = sx; int1 < sx + lot.info.width; int1++) {
            for (int int2 = sy; int2 < sy + lot.info.height; int2++) {
                for (int int3 = sz; int3 < int0; int3++) {
                    int int4 = int1 - sx;
                    int int5 = int2 - sy;
                    int int6 = int3 - sz;
                    if (int1 < this.width && int2 < this.height && int1 >= 0 && int2 >= 0 && int3 >= 0) {
                        int int7 = int4 + int5 * 10 + int6 * 100;
                        int int8 = lot.m_offsetInData[int7];
                        if (int8 != -1) {
                            int int9 = lot.m_data.getQuick(int8);
                            if (int9 > 0) {
                                boolean _boolean = false;

                                for (int int10 = 0; int10 < int9; int10++) {
                                    String string = (String)lot.info.tilesUsed.get(lot.m_data.getQuick(int8 + 1 + int10));
                                    IsoSprite isoSprite = (IsoSprite)IsoSpriteManager.instance.NamedMap.get(string);
                                    if (isoSprite == null) {
                                        Logger.getLogger(zombie.GameWindow.class.getName()).log(Level.SEVERE, "Missing tile definition: " + string);
                                    } else {
                                        IsoGridSquare isoGridSquare = this.getGridSquare(int1, int2, int3);
                                        if (isoGridSquare == null) {
                                            if (IsoGridSquare.loadGridSquareCache != null) {
                                                isoGridSquare = IsoGridSquare.getNew(IsoGridSquare.loadGridSquareCache, this, null, int1, int2, int3);
                                            } else {
                                                isoGridSquare = IsoGridSquare.getNew(this, null, int1, int2, int3);
                                            }

                                            this.ChunkMap[IsoPlayer.getPlayerIndex()].setGridSquare(isoGridSquare, int1, int2, int3);
                                        } else {
                                            if (bClearExisting
                                                && int10 == 0
                                                && isoSprite.getProperties().Is(IsoFlagType.solidfloor)
                                                && (!isoSprite.Properties.Is(IsoFlagType.hidewalls) || int9 > 1)) {
                                                _boolean = true;
                                            }

                                            if (_boolean && int10 == 0) {
                                                isoGridSquare.getObjects().clear();
                                            }
                                        }

                                        CellLoader.DoTileObjectCreation(isoSprite, isoSprite.getType(), isoGridSquare, this, int1, int2, int3, string);
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }

    public void PlaceLot(IsoLot lot, int sx, int sy, int sz, IsoChunk ch, int WX, int WY) {
        WX *= 10;
        WY *= 10;
        IsoMetaGrid isoMetaGrid = IsoWorld.instance.getMetaGrid();
        int int0 = Math.min(sz + lot.info.levels, sz + 8);

        try {
            for (int int1 = WX + sx; int1 < WX + sx + 10; int1++) {
                for (int int2 = WY + sy; int2 < WY + sy + 10; int2++) {
                    for (int int3 = sz; int3 < int0; int3++) {
                        int int4 = int1 - WX - sx;
                        int int5 = int2 - WY - sy;
                        int int6 = int3 - sz;
                        if (int1 < WX + 10 && int2 < WY + 10 && int1 >= WX && int2 >= WY && int3 >= 0) {
                            int int7 = int4 + int5 * 10 + int6 * 100;
                            int int8 = lot.m_offsetInData[int7];
                            if (int8 != -1) {
                                int int9 = lot.m_data.getQuick(int8);
                                if (int9 > 0) {
                                    IsoGridSquare isoGridSquare0 = ch.getGridSquare(int1 - WX, int2 - WY, int3);
                                    if (isoGridSquare0 == null) {
                                        if (IsoGridSquare.loadGridSquareCache != null) {
                                            isoGridSquare0 = IsoGridSquare.getNew(IsoGridSquare.loadGridSquareCache, this, null, int1, int2, int3);
                                        } else {
                                            isoGridSquare0 = IsoGridSquare.getNew(this, null, int1, int2, int3);
                                        }

                                        isoGridSquare0.setX(int1);
                                        isoGridSquare0.setY(int2);
                                        isoGridSquare0.setZ(int3);
                                        ch.setSquare(int1 - WX, int2 - WY, int3, isoGridSquare0);
                                    }

                                    for (int int10 = -1; int10 <= 1; int10++) {
                                        for (int int11 = -1; int11 <= 1; int11++) {
                                            if ((int10 != 0 || int11 != 0)
                                                && int10 + int1 - WX >= 0
                                                && int10 + int1 - WX < 10
                                                && int11 + int2 - WY >= 0
                                                && int11 + int2 - WY < 10) {
                                                IsoGridSquare isoGridSquare1 = ch.getGridSquare(int1 + int10 - WX, int2 + int11 - WY, int3);
                                                if (isoGridSquare1 == null) {
                                                    isoGridSquare1 = IsoGridSquare.getNew(this, null, int1 + int10, int2 + int11, int3);
                                                    ch.setSquare(int1 + int10 - WX, int2 + int11 - WY, int3, isoGridSquare1);
                                                }
                                            }
                                        }
                                    }

                                    RoomDef roomDef = isoMetaGrid.getRoomAt(int1, int2, int3);
                                    int int12 = roomDef != null ? roomDef.ID : -1;
                                    isoGridSquare0.setRoomID(int12);
                                    isoGridSquare0.ResetIsoWorldRegion();
                                    roomDef = isoMetaGrid.getEmptyOutsideAt(int1, int2, int3);
                                    if (roomDef != null) {
                                        IsoRoom isoRoom = ch.getRoom(roomDef.ID);
                                        isoGridSquare0.roofHideBuilding = isoRoom == null ? null : isoRoom.building;
                                    }

                                    boolean _boolean = true;

                                    for (int int13 = 0; int13 < int9; int13++) {
                                        String string = (String)lot.info.tilesUsed.get(lot.m_data.get(int8 + 1 + int13));
                                        if (!lot.info.bFixed2x) {
                                            string = IsoChunk.Fix2x(string);
                                        }

                                        IsoSprite isoSprite = (IsoSprite)IsoSpriteManager.instance.NamedMap.get(string);
                                        if (isoSprite == null) {
                                            Logger.getLogger(zombie.GameWindow.class.getName()).log(Level.SEVERE, "Missing tile definition: " + string);
                                        } else {
                                            if (int13 == 0
                                                && isoSprite.getProperties().Is(IsoFlagType.solidfloor)
                                                && (!isoSprite.Properties.Is(IsoFlagType.hidewalls) || int9 > 1)) {
                                                _boolean = true;
                                            }

                                            if (_boolean && int13 == 0) {
                                                isoGridSquare0.getObjects().clear();
                                            }

                                            CellLoader.DoTileObjectCreation(isoSprite, isoSprite.getType(), isoGridSquare0, this, int1, int2, int3, string);
                                        }
                                    }

                                    isoGridSquare0.FixStackableObjects();
                                }
                            }
                        }
                    }
                }
            }
        } catch (Exception exception) {
            DebugLog.log("Failed to load chunk, blocking out area");
            ExceptionLogger.logException(exception);

            for (int int14 = WX + sx; int14 < WX + sx + 10; int14++) {
                for (int int15 = WY + sy; int15 < WY + sy + 10; int15++) {
                    for (int int16 = sz; int16 < int0; int16++) {
                        ch.setSquare(int14 - WX - sx, int15 - WY - sy, int16 - sz, null);
                        this.setCacheGridSquare(int14, int15, int16, null);
                    }
                }
            }
        }
    }

    public void setDrag(KahluaTable kahluaTable, int _int) {
        if (_int >= 0 && _int < 4) {
            if (this.drag[_int] != null && this.drag[_int] != kahluaTable) {
                Object object = this.drag[_int].rawget("deactivate");
                if (object instanceof JavaFunction || object instanceof LuaClosure) {
                    LuaManager.caller.pcallvoid(LuaManager.thread, object, this.drag[_int]);
                }
            }

            this.drag[_int] = kahluaTable;
        }
    }

    public KahluaTable getDrag(int _int) {
        return _int >= 0 && _int < 4 ? this.drag[_int] : null;
    }

    public boolean DoBuilding(int player, boolean bRender) {
        boolean _boolean;
        try {
            IsoCell.s_performance.isoCellDoBuilding.start();
            _boolean = this.doBuildingInternal(player, bRender);
        } finally {
            IsoCell.s_performance.isoCellDoBuilding.end();
        }

        return _boolean;
    }

    private boolean doBuildingInternal(int _int, boolean _boolean) {
        if (UIManager.getPickedTile() != null && this.drag[_int] != null && JoypadManager.instance.getFromPlayer(_int) == null) {
            if (!IsoWorld.instance.isValidSquare((int)UIManager.getPickedTile().x, (int)UIManager.getPickedTile().y, (int)IsoCamera.CamCharacter.getZ())) {
                return false;
            }

            IsoGridSquare isoGridSquare = this.getGridSquare(
                (int)UIManager.getPickedTile().x, (int)UIManager.getPickedTile().y, (int)IsoCamera.CamCharacter.getZ()
            );
            if (!_boolean) {
                if (isoGridSquare == null) {
                    isoGridSquare = this.createNewGridSquare(
                        (int)UIManager.getPickedTile().x, (int)UIManager.getPickedTile().y, (int)IsoCamera.CamCharacter.getZ(), true
                    );
                    if (isoGridSquare == null) {
                        return false;
                    }
                }

                isoGridSquare.EnsureSurroundNotNull();
            }

            LuaEventManager.triggerEvent(
                "OnDoTileBuilding2",
                this.drag[_int],
                _boolean,
                (int)UIManager.getPickedTile().x,
                (int)UIManager.getPickedTile().y,
                (int)IsoCamera.CamCharacter.getZ(),
                isoGridSquare
            );
        }

        if (this.drag[_int] != null && JoypadManager.instance.getFromPlayer(_int) != null) {
            LuaEventManager.triggerEvent(
                "OnDoTileBuilding3",
                this.drag[_int],
                _boolean,
                (int)IsoPlayer.players[_int].getX(),
                (int)IsoPlayer.players[_int].getY(),
                (int)IsoCamera.CamCharacter.getZ()
            );
        }

        if (_boolean) {
            zombie.IndieGL.glBlendFunc(770, 771);
        }

        return false;
    }

    public float DistanceFromSupport(int x, int y, int z) {
        return 0.0F;
    }

    public ArrayList<IsoBuilding> getBuildingList() {
        return this.BuildingList;
    }

    public ArrayList<IsoWindow> getWindowList() {
        return this.WindowList;
    }

    public void addToWindowList(IsoWindow window) {
        if (!GameServer.bServer) {
            if (window != null) {
                if (!this.WindowList.contains(window)) {
                    this.WindowList.add(window);
                }
            }
        }
    }

    public void removeFromWindowList(IsoWindow window) {
        this.WindowList.remove(window);
    }

    public ArrayList<IsoMovingObject> getObjectList() {
        return this.ObjectList;
    }

    public IsoRoom getRoom(int ID) {
        return this.ChunkMap[IsoPlayer.getPlayerIndex()].getRoom(ID);
    }

    public ArrayList<IsoPushableObject> getPushableObjectList() {
        return this.PushableObjectList;
    }

    public HashMap<Integer, BuildingScore> getBuildingScores() {
        return this.BuildingScores;
    }

    public ArrayList<IsoRoom> getRoomList() {
        return this.RoomList;
    }

    public ArrayList<IsoObject> getStaticUpdaterObjectList() {
        return this.StaticUpdaterObjectList;
    }

    public ArrayList<IsoZombie> getZombieList() {
        return this.ZombieList;
    }

    public ArrayList<IsoGameCharacter> getRemoteSurvivorList() {
        return this.RemoteSurvivorList;
    }

    public ArrayList<IsoMovingObject> getRemoveList() {
        return this.removeList;
    }

    public ArrayList<IsoMovingObject> getAddList() {
        return this.addList;
    }

    public void addMovingObject(IsoMovingObject o) {
        this.addList.add(o);
    }

    public ArrayList<InventoryItem> getProcessItems() {
        return this.ProcessItems;
    }

    public ArrayList<IsoWorldInventoryObject> getProcessWorldItems() {
        return this.ProcessWorldItems;
    }

    public ArrayList<IsoObject> getProcessIsoObjects() {
        return this.ProcessIsoObject;
    }

    public ArrayList<InventoryItem> getProcessItemsRemove() {
        return this.ProcessItemsRemove;
    }

    public ArrayList<BaseVehicle> getVehicles() {
        return this.vehicles;
    }

    public int getHeight() {
        return this.height;
    }

    public void setHeight(int _height) {
        this.height = _height;
    }

    public int getWidth() {
        return this.width;
    }

    public void setWidth(int _width) {
        this.width = _width;
    }

    public int getWorldX() {
        return this.worldX;
    }

    public void setWorldX(int _worldX) {
        this.worldX = _worldX;
    }

    public int getWorldY() {
        return this.worldY;
    }

    public void setWorldY(int _worldY) {
        this.worldY = _worldY;
    }

    public boolean isSafeToAdd() {
        return this.safeToAdd;
    }

    public void setSafeToAdd(boolean _safeToAdd) {
        this.safeToAdd = _safeToAdd;
    }

    public Stack<IsoLightSource> getLamppostPositions() {
        return this.LamppostPositions;
    }

    public IsoLightSource getLightSourceAt(int x, int y, int z) {
        for (int _int = 0; _int < this.LamppostPositions.size(); _int++) {
            IsoLightSource isoLightSource = (IsoLightSource)this.LamppostPositions.get(_int);
            if (isoLightSource.getX() == x && isoLightSource.getY() == y && isoLightSource.getZ() == z) {
                return isoLightSource;
            }
        }

        return null;
    }

    public void addLamppost(IsoLightSource light) {
        if (light != null && !this.LamppostPositions.contains(light)) {
            this.LamppostPositions.add(light);
            IsoGridSquare.RecalcLightTime = -1;
            zombie.GameTime.instance.lightSourceUpdate = 100.0F;
        }
    }

    public IsoLightSource addLamppost(int x, int y, int z, float r, float g, float b, int rad) {
        IsoLightSource isoLightSource = new IsoLightSource(x, y, z, r, g, b, rad);
        this.LamppostPositions.add(isoLightSource);
        IsoGridSquare.RecalcLightTime = -1;
        zombie.GameTime.instance.lightSourceUpdate = 100.0F;
        return isoLightSource;
    }

    public void removeLamppost(int x, int y, int z) {
        for (int _int = 0; _int < this.LamppostPositions.size(); _int++) {
            IsoLightSource isoLightSource = (IsoLightSource)this.LamppostPositions.get(_int);
            if (isoLightSource.getX() == x && isoLightSource.getY() == y && isoLightSource.getZ() == z) {
                isoLightSource.clearInfluence();
                this.LamppostPositions.remove(isoLightSource);
                IsoGridSquare.RecalcLightTime = -1;
                zombie.GameTime.instance.lightSourceUpdate = 100.0F;
                return;
            }
        }
    }

    public void removeLamppost(IsoLightSource light) {
        light.life = 0;
        IsoGridSquare.RecalcLightTime = -1;
        zombie.GameTime.instance.lightSourceUpdate = 100.0F;
    }

    public int getCurrentLightX() {
        return this.currentLX;
    }

    public void setCurrentLightX(int _currentLX) {
        this.currentLX = _currentLX;
    }

    public int getCurrentLightY() {
        return this.currentLY;
    }

    public void setCurrentLightY(int _currentLY) {
        this.currentLY = _currentLY;
    }

    public int getCurrentLightZ() {
        return this.currentLZ;
    }

    public void setCurrentLightZ(int _currentLZ) {
        this.currentLZ = _currentLZ;
    }

    public int getMinX() {
        return this.minX;
    }

    public void setMinX(int _minX) {
        this.minX = _minX;
    }

    public int getMaxX() {
        return this.maxX;
    }

    public void setMaxX(int _maxX) {
        this.maxX = _maxX;
    }

    public int getMinY() {
        return this.minY;
    }

    public void setMinY(int _minY) {
        this.minY = _minY;
    }

    public int getMaxY() {
        return this.maxY;
    }

    public void setMaxY(int _maxY) {
        this.maxY = _maxY;
    }

    public int getMinZ() {
        return this.minZ;
    }

    public void setMinZ(int _minZ) {
        this.minZ = _minZ;
    }

    public int getMaxZ() {
        return this.maxZ;
    }

    public void setMaxZ(int _maxZ) {
        this.maxZ = _maxZ;
    }

    public OnceEvery getDangerUpdate() {
        return this.dangerUpdate;
    }

    public void setDangerUpdate(OnceEvery _dangerUpdate) {
        this.dangerUpdate = _dangerUpdate;
    }

    public Thread getLightInfoUpdate() {
        return this.LightInfoUpdate;
    }

    public void setLightInfoUpdate(Thread _LightInfoUpdate) {
        this.LightInfoUpdate = _LightInfoUpdate;
    }

    public ArrayList<IsoSurvivor> getSurvivorList() {
        return this.SurvivorList;
    }

    public static int getRComponent(int col) {
        return col & 0xFF;
    }

    public static int getGComponent(int col) {
        return (col & 0xFF00) >> 8;
    }

    public static int getBComponent(int col) {
        return (col & 0xFF0000) >> 16;
    }

    public static int toIntColor(float r, float g, float b, float a) {
        return (int)(r * 255.0F) << 0 | (int)(g * 255.0F) << 8 | (int)(b * 255.0F) << 16 | (int)(a * 255.0F) << 24;
    }

    public IsoGridSquare getRandomOutdoorTile() {
        IsoGridSquare isoGridSquare = null;

        do {
            isoGridSquare = this.getGridSquare(
                this.ChunkMap[IsoPlayer.getPlayerIndex()].getWorldXMin() * 10 + Rand.Next(this.width),
                this.ChunkMap[IsoPlayer.getPlayerIndex()].getWorldYMin() * 10 + Rand.Next(this.height),
                0
            );
            if (isoGridSquare != null) {
                isoGridSquare.setCachedIsFree(false);
            }
        } while (isoGridSquare == null || !isoGridSquare.isFree(false) || isoGridSquare.getRoom() != null);

        return isoGridSquare;
    }

    private static void InsertAt(int int1, BuildingScore buildingScore1, BuildingScore[] buildingScore0) {
        for (int int0 = buildingScore0.length - 1; int0 > int1; int0--) {
            buildingScore0[int0] = buildingScore0[int0 - 1];
        }

        buildingScore0[int1] = buildingScore1;
    }

    static void Place(BuildingScore buildingScore1, BuildingScore[] buildingScore0, IsoCell.BuildingSearchCriteria buildingSearchCriteria) {
        for (int _int = 0; _int < buildingScore0.length; _int++) {
            if (buildingScore0[_int] != null) {
                boolean _boolean = false;
                if (buildingScore0[_int] == null) {
                    _boolean = true;
                } else {
                    switch (buildingSearchCriteria) {
                        case General:
                            if (buildingScore0[_int].food + buildingScore0[_int].defense + (float)buildingScore0[_int].size + buildingScore0[_int].weapons
                                < buildingScore1.food + buildingScore1.defense + (float)buildingScore1.size + buildingScore1.weapons) {
                                _boolean = true;
                            }
                            break;
                        case Food:
                            if (buildingScore0[_int].food < buildingScore1.food) {
                                _boolean = true;
                            }
                            break;
                        case Wood:
                            if (buildingScore0[_int].wood < buildingScore1.wood) {
                                _boolean = true;
                            }
                            break;
                        case Weapons:
                            if (buildingScore0[_int].weapons < buildingScore1.weapons) {
                                _boolean = true;
                            }
                            break;
                        case Defense:
                            if (buildingScore0[_int].defense < buildingScore1.defense) {
                                _boolean = true;
                            }
                    }
                }

                if (_boolean) {
                    InsertAt(_int, buildingScore1, buildingScore0);
                    return;
                }
            }
        }
    }

    public Stack<BuildingScore> getBestBuildings(IsoCell.BuildingSearchCriteria criteria, int count) {
        BuildingScore[] buildingScore0 = new BuildingScore[count];
        if (this.BuildingScores.isEmpty()) {
            int int0 = this.BuildingList.size();

            for (int int1 = 0; int1 < int0; int1++) {
                ((IsoBuilding)this.BuildingList.get(int1)).update();
            }
        }

        int int2 = this.BuildingScores.size();

        for (int int3 = 0; int3 < int2; int3++) {
            BuildingScore buildingScore1 = (BuildingScore)this.BuildingScores.get(int3);
            Place(buildingScore1, buildingScore0, criteria);
        }

        buildingscores.clear();
        buildingscores.addAll(Arrays.asList(buildingScore0));
        return buildingscores;
    }

    public boolean blocked(Mover mover, int x, int y, int z, int lx, int ly, int lz) {
        IsoGridSquare isoGridSquare = this.getGridSquare(lx, ly, lz);
        if (isoGridSquare == null) {
            return true;
        } else {
            if (mover instanceof IsoMovingObject) {
                if (isoGridSquare.testPathFindAdjacent((IsoMovingObject)mover, x - lx, y - ly, z - lz)) {
                    return true;
                }
            } else if (isoGridSquare.testPathFindAdjacent(null, x - lx, y - ly, z - lz)) {
                return true;
            }

            return false;
        }
    }

    public void Dispose() {
        for (int int0 = 0; int0 < this.ObjectList.size(); int0++) {
            IsoMovingObject isoMovingObject = (IsoMovingObject)this.ObjectList.get(int0);
            if (isoMovingObject instanceof IsoZombie) {
                isoMovingObject.setCurrent(null);
                isoMovingObject.setLast(null);
                zombie.VirtualZombieManager.instance.addToReusable((IsoZombie)isoMovingObject);
            }
        }

        for (int int1 = 0; int1 < this.RoomList.size(); int1++) {
            ((IsoRoom)this.RoomList.get(int1)).TileList.clear();
            ((IsoRoom)this.RoomList.get(int1)).Exits.clear();
            ((IsoRoom)this.RoomList.get(int1)).WaterSources.clear();
            ((IsoRoom)this.RoomList.get(int1)).lightSwitches.clear();
            ((IsoRoom)this.RoomList.get(int1)).Beds.clear();
        }

        for (int int2 = 0; int2 < this.BuildingList.size(); int2++) {
            ((IsoBuilding)this.BuildingList.get(int2)).Exits.clear();
            ((IsoBuilding)this.BuildingList.get(int2)).Rooms.clear();
            ((IsoBuilding)this.BuildingList.get(int2)).container.clear();
            ((IsoBuilding)this.BuildingList.get(int2)).Windows.clear();
        }

        LuaEventManager.clear();
        LuaHookManager.clear();
        this.LamppostPositions.clear();
        this.ProcessItems.clear();
        this.ProcessItemsRemove.clear();
        this.ProcessWorldItems.clear();
        this.ProcessWorldItemsRemove.clear();
        this.BuildingScores.clear();
        this.BuildingList.clear();
        this.WindowList.clear();
        this.PushableObjectList.clear();
        this.RoomList.clear();
        this.SurvivorList.clear();
        this.ObjectList.clear();
        this.ZombieList.clear();

        for (int int3 = 0; int3 < this.ChunkMap.length; int3++) {
            this.ChunkMap[int3].Dispose();
            this.ChunkMap[int3] = null;
        }

        for (int int4 = 0; int4 < this.gridSquares.length; int4++) {
            if (this.gridSquares[int4] != null) {
                Arrays.fill(this.gridSquares[int4], null);
                this.gridSquares[int4] = null;
            }
        }
    }

    @LuaMethod(
        name = "getGridSquare"
    )
    public IsoGridSquare getGridSquare(double x, double y, double z) {
        return GameServer.bServer ? ServerMap.instance.getGridSquare((int)x, (int)y, (int)z) : this.getGridSquare((int)x, (int)y, (int)z);
    }

    @LuaMethod(
        name = "getOrCreateGridSquare"
    )
    public IsoGridSquare getOrCreateGridSquare(double x, double y, double z) {
        if (GameServer.bServer) {
            IsoGridSquare isoGridSquare0 = ServerMap.instance.getGridSquare((int)x, (int)y, (int)z);
            if (isoGridSquare0 == null) {
                isoGridSquare0 = IsoGridSquare.getNew(this, null, (int)x, (int)y, (int)z);
                ServerMap.instance.setGridSquare((int)x, (int)y, (int)z, isoGridSquare0);
                this.ConnectNewSquare(isoGridSquare0, true);
            }

            return isoGridSquare0;
        } else {
            IsoGridSquare isoGridSquare1 = this.getGridSquare((int)x, (int)y, (int)z);
            if (isoGridSquare1 == null) {
                isoGridSquare1 = IsoGridSquare.getNew(this, null, (int)x, (int)y, (int)z);
                this.ConnectNewSquare(isoGridSquare1, true);
            }

            return isoGridSquare1;
        }
    }

    public void setCacheGridSquare(int x, int y, int z, IsoGridSquare square) {
        assert square == null || x == square.getX() && y == square.getY() && z == square.getZ();

        if (!GameServer.bServer) {
            assert this.getChunkForGridSquare(x, y, z) != null;

            int int0 = IsoChunkMap.ChunkWidthInTiles;

            for (int int1 = 0; int1 < IsoPlayer.numPlayers; int1++) {
                if (!this.ChunkMap[int1].ignore) {
                    this.ChunkMap[int1].YMinTiles = -1;
                    this.ChunkMap[int1].XMinTiles = -1;
                    this.ChunkMap[int1].YMaxTiles = -1;
                    this.ChunkMap[int1].XMaxTiles = -1;
                    int int2 = x - this.ChunkMap[int1].getWorldXMinTiles();
                    int int3 = y - this.ChunkMap[int1].getWorldYMinTiles();
                    if (z < 8 && z >= 0 && int2 >= 0 && int2 < int0 && int3 >= 0 && int3 < int0) {
                        this.gridSquares[int1][int2 + int3 * int0 + z * int0 * int0] = square;
                    }
                }
            }
        }
    }

    public void setCacheChunk(IsoChunk chunk) {
        if (!GameServer.bServer) {
            for (int _int = 0; _int < IsoPlayer.numPlayers; _int++) {
                this.setCacheChunk(chunk, _int);
            }
        }
    }

    public void setCacheChunk(IsoChunk chunk, int playerIndex) {
        if (!GameServer.bServer) {
            int int0 = IsoChunkMap.ChunkWidthInTiles;
            IsoChunkMap isoChunkMap = this.ChunkMap[playerIndex];
            if (!isoChunkMap.ignore) {
                int int1 = chunk.wx - isoChunkMap.getWorldXMin();
                int int2 = chunk.wy - isoChunkMap.getWorldYMin();
                if (int1 >= 0 && int1 < IsoChunkMap.ChunkGridWidth && int2 >= 0 && int2 < IsoChunkMap.ChunkGridWidth) {
                    IsoGridSquare[] isoGridSquare0 = this.gridSquares[playerIndex];

                    for (int int3 = 0; int3 < 8; int3++) {
                        for (int int4 = 0; int4 < 10; int4++) {
                            for (int int5 = 0; int5 < 10; int5++) {
                                IsoGridSquare isoGridSquare1 = chunk.squares[int3][int5 + int4 * 10];
                                int int6 = int1 * 10 + int5;
                                int int7 = int2 * 10 + int4;
                                isoGridSquare0[int6 + int7 * int0 + int3 * int0 * int0] = isoGridSquare1;
                            }
                        }
                    }
                }
            }
        }
    }

    public void clearCacheGridSquare(int playerIndex) {
        if (!GameServer.bServer) {
            int _int = IsoChunkMap.ChunkWidthInTiles;
            this.gridSquares[playerIndex] = new IsoGridSquare[_int * _int * 8];
        }
    }

    public void setCacheGridSquareLocal(int x, int y, int z, IsoGridSquare square, int playerIndex) {
        if (!GameServer.bServer) {
            int _int = IsoChunkMap.ChunkWidthInTiles;
            if (z < 8 && z >= 0 && x >= 0 && x < _int && y >= 0 && y < _int) {
                this.gridSquares[playerIndex][x + y * _int + z * _int * _int] = square;
            }
        }
    }

    public IsoGridSquare getGridSquare(Double x, Double y, Double z) {
        return this.getGridSquare(x.intValue(), y.intValue(), z.intValue());
    }

    public IsoGridSquare getGridSquare(int x, int y, int z) {
        if (GameServer.bServer) {
            return ServerMap.instance.getGridSquare(x, y, z);
        } else {
            int int0 = IsoChunkMap.ChunkWidthInTiles;

            for (int int1 = 0; int1 < IsoPlayer.numPlayers; int1++) {
                if (!this.ChunkMap[int1].ignore) {
                    if (z == 0) {
                        boolean _boolean = false;
                    }

                    int int2 = x - this.ChunkMap[int1].getWorldXMinTiles();
                    int int3 = y - this.ChunkMap[int1].getWorldYMinTiles();
                    if (z < 8 && z >= 0 && int2 >= 0 && int2 < int0 && int3 >= 0 && int3 < int0) {
                        IsoGridSquare isoGridSquare = this.gridSquares[int1][int2 + int3 * int0 + z * int0 * int0];
                        if (isoGridSquare != null) {
                            return isoGridSquare;
                        }
                    }
                }
            }

            return null;
        }
    }

    public void EnsureSurroundNotNull(int xx, int yy, int zz) {
        for (int int0 = -1; int0 <= 1; int0++) {
            for (int int1 = -1; int1 <= 1; int1++) {
                this.createNewGridSquare(xx + int0, yy + int1, zz, false);
            }
        }
    }

    public void DeleteAllMovingObjects() {
        this.ObjectList.clear();
    }

    @LuaMethod(
        name = "getMaxFloors"
    )
    public int getMaxFloors() {
        return 8;
    }

    public KahluaTable getLuaObjectList() {
        KahluaTable kahluaTable = LuaManager.platform.newTable();
        LuaManager.env.rawset("Objects", kahluaTable);

        for (int _int = 0; _int < this.ObjectList.size(); _int++) {
            kahluaTable.rawset(_int + 1, this.ObjectList.get(_int));
        }

        return kahluaTable;
    }

    public int getHeightInTiles() {
        return this.ChunkMap[IsoPlayer.getPlayerIndex()].getWidthInTiles();
    }

    public int getWidthInTiles() {
        return this.ChunkMap[IsoPlayer.getPlayerIndex()].getWidthInTiles();
    }

    public boolean isNull(int x, int y, int z) {
        IsoGridSquare isoGridSquare = this.getGridSquare(x, y, z);
        return isoGridSquare == null || !isoGridSquare.isFree(false);
    }

    public void Remove(IsoMovingObject obj) {
        if (!(obj instanceof IsoPlayer) || ((IsoPlayer)obj).isDead()) {
            this.removeList.add(obj);
        }
    }

    boolean isBlocked(IsoGridSquare isoGridSquare1, IsoGridSquare isoGridSquare0) {
        return isoGridSquare1.room != isoGridSquare0.room;
    }

    private int CalculateColor(
        IsoGridSquare isoGridSquare1, IsoGridSquare isoGridSquare2, IsoGridSquare isoGridSquare3, IsoGridSquare isoGridSquare0, int int1, int int0
    ) {
        float float0 = 0.0F;
        float float1 = 0.0F;
        float float2 = 0.0F;
        float float3 = 1.0F;
        if (isoGridSquare0 == null) {
            return 0;
        } else {
            float float4 = 0.0F;
            boolean _boolean = true;
            if (isoGridSquare1 != null && isoGridSquare0.room == isoGridSquare1.room && isoGridSquare1.getChunk() != null) {
                float4++;
                ColorInfo colorInfo0 = isoGridSquare1.lighting[int0].lightInfo();
                float0 += colorInfo0.r;
                float1 += colorInfo0.g;
                float2 += colorInfo0.b;
            }

            if (isoGridSquare2 != null && isoGridSquare0.room == isoGridSquare2.room && isoGridSquare2.getChunk() != null) {
                float4++;
                ColorInfo colorInfo1 = isoGridSquare2.lighting[int0].lightInfo();
                float0 += colorInfo1.r;
                float1 += colorInfo1.g;
                float2 += colorInfo1.b;
            }

            if (isoGridSquare3 != null && isoGridSquare0.room == isoGridSquare3.room && isoGridSquare3.getChunk() != null) {
                float4++;
                ColorInfo colorInfo2 = isoGridSquare3.lighting[int0].lightInfo();
                float0 += colorInfo2.r;
                float1 += colorInfo2.g;
                float2 += colorInfo2.b;
            }

            if (isoGridSquare0 != null) {
                float4++;
                ColorInfo colorInfo3 = isoGridSquare0.lighting[int0].lightInfo();
                float0 += colorInfo3.r;
                float1 += colorInfo3.g;
                float2 += colorInfo3.b;
            }

            if (float4 != 0.0F) {
                float0 /= float4;
                float1 /= float4;
                float2 /= float4;
            }

            if (float0 > 1.0F) {
                float0 = 1.0F;
            }

            if (float1 > 1.0F) {
                float1 = 1.0F;
            }

            if (float2 > 1.0F) {
                float2 = 1.0F;
            }

            if (float0 < 0.0F) {
                float0 = 0.0F;
            }

            if (float1 < 0.0F) {
                float1 = 0.0F;
            }

            if (float2 < 0.0F) {
                float2 = 0.0F;
            }

            if (isoGridSquare0 != null) {
                isoGridSquare0.setVertLight(int1, (int)(float0 * 255.0F) << 0 | (int)(float1 * 255.0F) << 8 | (int)(float2 * 255.0F) << 16 | 0xFF000000, int0);
                isoGridSquare0.setVertLight(
                    int1 + 4, (int)(float0 * 255.0F) << 0 | (int)(float1 * 255.0F) << 8 | (int)(float2 * 255.0F) << 16 | 0xFF000000, int0
                );
            }

            return int1;
        }
    }

    public static IsoCell getInstance() {
        return instance;
    }

    public void render() {
        IsoCell.s_performance.isoCellRender.invokeAndMeasure(this, IsoCell::renderInternal);
    }

    private void renderInternal() {
        int int0 = IsoCamera.frameState.playerIndex;
        IsoPlayer isoPlayer0 = IsoPlayer.players[int0];
        if (isoPlayer0.dirtyRecalcGridStackTime > 0.0F) {
            isoPlayer0.dirtyRecalcGridStack = true;
        } else {
            isoPlayer0.dirtyRecalcGridStack = false;
        }

        if (!PerformanceSettings.NewRoofHiding) {
            if (this.bHideFloors[int0] && this.unhideFloorsCounter[int0] > 0) {
                this.unhideFloorsCounter[int0]--;
            }

            if (this.unhideFloorsCounter[int0] <= 0) {
                this.bHideFloors[int0] = false;
                this.unhideFloorsCounter[int0] = 60;
            }
        }

        int int1 = 8;
        if (int1 < 8) {
            int1++;
        }

        this.recalcShading--;
        byte byte0 = 0;
        byte byte1 = 0;
        int int2 = byte0 + IsoCamera.getOffscreenWidth(int0);
        int int3 = byte1 + IsoCamera.getOffscreenHeight(int0);
        float float0 = IsoUtils.XToIso((float)byte0, (float)byte1, 0.0F);
        float float1 = IsoUtils.YToIso((float)int2, (float)byte1, 0.0F);
        float float2 = IsoUtils.XToIso((float)int2, (float)int3, 6.0F);
        float float3 = IsoUtils.YToIso((float)byte0, (float)int3, 6.0F);
        this.minY = (int)float1;
        this.maxY = (int)float3;
        this.minX = (int)float0;
        this.maxX = (int)float2;
        this.minX -= 2;
        this.minY -= 2;
        this.maxZ = MaxHeight;
        if (IsoCamera.CamCharacter == null) {
            this.maxZ = 1;
        }

        byte byte2 = 0;
        byte2 = 4;
        if (zombie.GameTime.instance.FPSMultiplier > 1.5F) {
            byte2 = 6;
        }

        if (this.minX != this.lastMinX || this.minY != this.lastMinY) {
            this.lightUpdateCount = 10;
        }

        if (!PerformanceSettings.NewRoofHiding) {
            IsoGridSquare isoGridSquare0 = IsoCamera.CamCharacter == null ? null : IsoCamera.CamCharacter.getCurrentSquare();
            if (isoGridSquare0 != null) {
                IsoGridSquare isoGridSquare1 = this.getGridSquare(
                    (double)Math.round(IsoCamera.CamCharacter.getX()), (double)Math.round(IsoCamera.CamCharacter.getY()), (double)IsoCamera.CamCharacter.getZ()
                );
                if (isoGridSquare1 != null && this.IsBehindStuff(isoGridSquare1)) {
                    this.bHideFloors[int0] = true;
                }

                if (!this.bHideFloors[int0] && isoGridSquare0.getProperties().Is(IsoFlagType.hidewalls)
                    || !isoGridSquare0.getProperties().Is(IsoFlagType.exterior)) {
                    this.bHideFloors[int0] = true;
                }
            }

            if (this.bHideFloors[int0]) {
                this.maxZ = (int)IsoCamera.CamCharacter.getZ() + 1;
            }
        }

        if (PerformanceSettings.LightingFrameSkip < 3) {
            this.DrawStencilMask();
        }

        if (PerformanceSettings.LightingFrameSkip == 3) {
            int int4 = IsoCamera.getOffscreenWidth(int0) / 2;
            int int5 = IsoCamera.getOffscreenHeight(int0) / 2;
            short _short = 409;
            int4 -= _short / (2 / Core.TileScale);
            int5 -= _short / (2 / Core.TileScale);
            this.StencilX1 = int4 - (int)IsoCamera.cameras[int0].RightClickX;
            this.StencilY1 = int5 - (int)IsoCamera.cameras[int0].RightClickY;
            this.StencilX2 = this.StencilX1 + _short * Core.TileScale;
            this.StencilY2 = this.StencilY1 + _short * Core.TileScale;
        }

        if (PerformanceSettings.NewRoofHiding && isoPlayer0.dirtyRecalcGridStack) {
            this.hidesOrphanStructuresAbove = int1;
            IsoGridSquare isoGridSquare2 = null;
            ((ArrayList)this.otherOccluderBuildings.get(int0)).clear();
            if (this.otherOccluderBuildingsArr[int0] != null) {
                this.otherOccluderBuildingsArr[int0][0] = null;
            } else {
                this.otherOccluderBuildingsArr[int0] = new IsoBuilding[500];
            }

            if (IsoCamera.CamCharacter != null && IsoCamera.CamCharacter.getCurrentSquare() != null) {
                IsoGridSquare isoGridSquare3 = IsoCamera.CamCharacter.getCurrentSquare();
                int int6 = 10;
                if (this.ZombieList.size() < 10) {
                    int6 = this.ZombieList.size();
                }

                if (this.nearestVisibleZombie[int0] != null) {
                    if (this.nearestVisibleZombie[int0].isDead()) {
                        this.nearestVisibleZombie[int0] = null;
                    } else {
                        float float4 = this.nearestVisibleZombie[int0].x - IsoCamera.CamCharacter.x;
                        float float5 = this.nearestVisibleZombie[int0].y - IsoCamera.CamCharacter.y;
                        this.nearestVisibleZombieDistSqr[int0] = float4 * float4 + float5 * float5;
                    }
                }

                for (int int7 = 0; int7 < int6; this.zombieScanCursor++) {
                    if (this.zombieScanCursor >= this.ZombieList.size()) {
                        this.zombieScanCursor = 0;
                    }

                    IsoZombie isoZombie = (IsoZombie)this.ZombieList.get(this.zombieScanCursor);
                    if (isoZombie != null) {
                        IsoGridSquare isoGridSquare4 = isoZombie.getCurrentSquare();
                        if (isoGridSquare4 != null && isoGridSquare3.z == isoGridSquare4.z && isoGridSquare4.getCanSee(int0)) {
                            if (this.nearestVisibleZombie[int0] == null) {
                                this.nearestVisibleZombie[int0] = isoZombie;
                                float float6 = this.nearestVisibleZombie[int0].x - IsoCamera.CamCharacter.x;
                                float float7 = this.nearestVisibleZombie[int0].y - IsoCamera.CamCharacter.y;
                                this.nearestVisibleZombieDistSqr[int0] = float6 * float6 + float7 * float7;
                            } else {
                                float float8 = isoZombie.x - IsoCamera.CamCharacter.x;
                                float float9 = isoZombie.y - IsoCamera.CamCharacter.y;
                                float float10 = float8 * float8 + float9 * float9;
                                if (float10 < this.nearestVisibleZombieDistSqr[int0]) {
                                    this.nearestVisibleZombie[int0] = isoZombie;
                                    this.nearestVisibleZombieDistSqr[int0] = float10;
                                }
                            }
                        }
                    }

                    int7++;
                }

                for (int int8 = 0; int8 < 4; int8++) {
                    IsoPlayer isoPlayer1 = IsoPlayer.players[int8];
                    if (isoPlayer1 != null && isoPlayer1.getCurrentSquare() != null) {
                        IsoGridSquare isoGridSquare5 = isoPlayer1.getCurrentSquare();
                        if (int8 == int0) {
                            isoGridSquare2 = isoGridSquare5;
                        }

                        double double0 = (double)isoPlayer1.x - Math.floor((double)isoPlayer1.x);
                        double double1 = (double)isoPlayer1.y - Math.floor((double)isoPlayer1.y);
                        boolean boolean0 = double0 > double1;
                        if (this.lastPlayerAngle[int8] == null) {
                            this.lastPlayerAngle[int8] = new Vector2(isoPlayer1.getForwardDirection());
                            this.playerCutawaysDirty[int8] = true;
                        } else if (isoPlayer1.getForwardDirection().dot(this.lastPlayerAngle[int8]) < 0.98F) {
                            this.lastPlayerAngle[int8].set(isoPlayer1.getForwardDirection());
                            this.playerCutawaysDirty[int8] = true;
                        }

                        IsoDirections isoDirections0 = IsoDirections.fromAngle(isoPlayer1.getForwardDirection());
                        if (this.lastPlayerSquare[int8] != isoGridSquare5
                            || this.lastPlayerSquareHalf[int8] != boolean0
                            || this.lastPlayerDir[int8] != isoDirections0) {
                            this.playerCutawaysDirty[int8] = true;
                            this.lastPlayerSquare[int8] = isoGridSquare5;
                            this.lastPlayerSquareHalf[int8] = boolean0;
                            this.lastPlayerDir[int8] = isoDirections0;
                            IsoBuilding isoBuilding0 = isoGridSquare5.getBuilding();
                            this.playerWindowPeekingRoomId[int8] = -1;
                            this.GetBuildingsInFrontOfCharacter((ArrayList<IsoBuilding>)this.playerOccluderBuildings.get(int8), isoGridSquare5, boolean0);
                            if (this.playerOccluderBuildingsArr[int0] == null) {
                                this.playerOccluderBuildingsArr[int0] = new IsoBuilding[500];
                            }

                            this.playerHidesOrphanStructures[int8] = this.bOccludedByOrphanStructureFlag;
                            if (isoBuilding0 == null && !isoPlayer1.bRemote) {
                                isoBuilding0 = this.GetPeekedInBuilding(isoGridSquare5, isoDirections0);
                                if (isoBuilding0 != null) {
                                    this.playerWindowPeekingRoomId[int8] = this.playerPeekedRoomId;
                                }
                            }

                            if (isoBuilding0 != null) {
                                this.AddUniqueToBuildingList((ArrayList<IsoBuilding>)this.playerOccluderBuildings.get(int8), isoBuilding0);
                            }

                            ArrayList arrayList0 = (ArrayList)this.playerOccluderBuildings.get(int8);

                            for (int int9 = 0; int9 < arrayList0.size(); int9++) {
                                IsoBuilding isoBuilding1 = (IsoBuilding)arrayList0.get(int9);
                                this.playerOccluderBuildingsArr[int0][int9] = isoBuilding1;
                            }

                            this.playerOccluderBuildingsArr[int0][arrayList0.size()] = null;
                        }

                        if (int8 == int0 && isoGridSquare2 != null) {
                            this.gridSquaresTempLeft.clear();
                            this.gridSquaresTempRight.clear();
                            this.GetSquaresAroundPlayerSquare(isoPlayer1, isoGridSquare2, this.gridSquaresTempLeft, this.gridSquaresTempRight);

                            for (int int10 = 0; int10 < this.gridSquaresTempLeft.size(); int10++) {
                                IsoGridSquare isoGridSquare6 = (IsoGridSquare)this.gridSquaresTempLeft.get(int10);
                                if (isoGridSquare6.getCanSee(int0)
                                    && (isoGridSquare6.getBuilding() == null || isoGridSquare6.getBuilding() == isoGridSquare2.getBuilding())) {
                                    ArrayList arrayList1 = this.GetBuildingsInFrontOfMustSeeSquare(isoGridSquare6, IsoGridOcclusionData.OcclusionFilter.Right);

                                    for (int int11 = 0; int11 < arrayList1.size(); int11++) {
                                        this.AddUniqueToBuildingList(
                                            (ArrayList<IsoBuilding>)this.otherOccluderBuildings.get(int0), (IsoBuilding)arrayList1.get(int11)
                                        );
                                    }

                                    this.playerHidesOrphanStructures[int0] = this.playerHidesOrphanStructures[int0] | this.bOccludedByOrphanStructureFlag;
                                }
                            }

                            for (int int12 = 0; int12 < this.gridSquaresTempRight.size(); int12++) {
                                IsoGridSquare isoGridSquare7 = (IsoGridSquare)this.gridSquaresTempRight.get(int12);
                                if (isoGridSquare7.getCanSee(int0)
                                    && (isoGridSquare7.getBuilding() == null || isoGridSquare7.getBuilding() == isoGridSquare2.getBuilding())) {
                                    ArrayList arrayList2 = this.GetBuildingsInFrontOfMustSeeSquare(isoGridSquare7, IsoGridOcclusionData.OcclusionFilter.Left);

                                    for (int int13 = 0; int13 < arrayList2.size(); int13++) {
                                        this.AddUniqueToBuildingList(
                                            (ArrayList<IsoBuilding>)this.otherOccluderBuildings.get(int0), (IsoBuilding)arrayList2.get(int13)
                                        );
                                    }

                                    this.playerHidesOrphanStructures[int0] = this.playerHidesOrphanStructures[int0] | this.bOccludedByOrphanStructureFlag;
                                }
                            }

                            ArrayList arrayList3 = (ArrayList)this.otherOccluderBuildings.get(int0);
                            if (this.otherOccluderBuildingsArr[int0] == null) {
                                this.otherOccluderBuildingsArr[int0] = new IsoBuilding[500];
                            }

                            for (int int14 = 0; int14 < arrayList3.size(); int14++) {
                                IsoBuilding isoBuilding2 = (IsoBuilding)arrayList3.get(int14);
                                this.otherOccluderBuildingsArr[int0][int14] = isoBuilding2;
                            }

                            this.otherOccluderBuildingsArr[int0][arrayList3.size()] = null;
                        }

                        if (this.playerHidesOrphanStructures[int8] && this.hidesOrphanStructuresAbove > isoGridSquare5.getZ()) {
                            this.hidesOrphanStructuresAbove = isoGridSquare5.getZ();
                        }
                    }
                }

                if (isoGridSquare2 != null && this.hidesOrphanStructuresAbove < isoGridSquare2.getZ()) {
                    this.hidesOrphanStructuresAbove = isoGridSquare2.getZ();
                }

                boolean boolean1 = false;
                if (this.nearestVisibleZombie[int0] != null && this.nearestVisibleZombieDistSqr[int0] < 150.0F) {
                    IsoGridSquare isoGridSquare8 = this.nearestVisibleZombie[int0].getCurrentSquare();
                    if (isoGridSquare8 != null && isoGridSquare8.getCanSee(int0)) {
                        double double2 = (double)this.nearestVisibleZombie[int0].x - Math.floor((double)this.nearestVisibleZombie[int0].x);
                        double double3 = (double)this.nearestVisibleZombie[int0].y - Math.floor((double)this.nearestVisibleZombie[int0].y);
                        boolean boolean2 = double2 > double3;
                        boolean1 = true;
                        if (this.lastZombieSquare[int0] != isoGridSquare8 || this.lastZombieSquareHalf[int0] != boolean2) {
                            this.lastZombieSquare[int0] = isoGridSquare8;
                            this.lastZombieSquareHalf[int0] = boolean2;
                            this.GetBuildingsInFrontOfCharacter((ArrayList<IsoBuilding>)this.zombieOccluderBuildings.get(int0), isoGridSquare8, boolean2);
                            ArrayList arrayList4 = (ArrayList)this.zombieOccluderBuildings.get(int0);
                            if (this.zombieOccluderBuildingsArr[int0] == null) {
                                this.zombieOccluderBuildingsArr[int0] = new IsoBuilding[500];
                            }

                            for (int int15 = 0; int15 < arrayList4.size(); int15++) {
                                IsoBuilding isoBuilding3 = (IsoBuilding)arrayList4.get(int15);
                                this.zombieOccluderBuildingsArr[int0][int15] = isoBuilding3;
                            }

                            this.zombieOccluderBuildingsArr[int0][arrayList4.size()] = null;
                        }
                    }
                }

                if (!boolean1) {
                    ((ArrayList)this.zombieOccluderBuildings.get(int0)).clear();
                    if (this.zombieOccluderBuildingsArr[int0] != null) {
                        this.zombieOccluderBuildingsArr[int0][0] = null;
                    } else {
                        this.zombieOccluderBuildingsArr[int0] = new IsoBuilding[500];
                    }
                }
            } else {
                for (int int16 = 0; int16 < 4; int16++) {
                    ((ArrayList)this.playerOccluderBuildings.get(int16)).clear();
                    if (this.playerOccluderBuildingsArr[int16] != null) {
                        this.playerOccluderBuildingsArr[int16][0] = null;
                    } else {
                        this.playerOccluderBuildingsArr[int16] = new IsoBuilding[500];
                    }

                    this.lastPlayerSquare[int16] = null;
                    this.playerCutawaysDirty[int16] = true;
                }

                this.playerWindowPeekingRoomId[int0] = -1;
                ((ArrayList)this.zombieOccluderBuildings.get(int0)).clear();
                if (this.zombieOccluderBuildingsArr[int0] != null) {
                    this.zombieOccluderBuildingsArr[int0][0] = null;
                } else {
                    this.zombieOccluderBuildingsArr[int0] = new IsoBuilding[500];
                }

                this.lastZombieSquare[int0] = null;
            }
        }

        if (!PerformanceSettings.NewRoofHiding) {
            for (int int17 = 0; int17 < IsoPlayer.numPlayers; int17++) {
                this.playerWindowPeekingRoomId[int17] = -1;
                IsoPlayer isoPlayer2 = IsoPlayer.players[int17];
                if (isoPlayer2 != null) {
                    IsoBuilding isoBuilding4 = isoPlayer2.getCurrentBuilding();
                    if (isoBuilding4 == null) {
                        IsoDirections isoDirections1 = IsoDirections.fromAngle(isoPlayer2.getForwardDirection());
                        isoBuilding4 = this.GetPeekedInBuilding(isoPlayer2.getCurrentSquare(), isoDirections1);
                        if (isoBuilding4 != null) {
                            this.playerWindowPeekingRoomId[int17] = this.playerPeekedRoomId;
                        }
                    }
                }
            }
        }

        if (IsoCamera.CamCharacter != null
            && IsoCamera.CamCharacter.getCurrentSquare() != null
            && IsoCamera.CamCharacter.getCurrentSquare().getProperties().Is(IsoFlagType.hidewalls)) {
            this.maxZ = (int)IsoCamera.CamCharacter.getZ() + 1;
        }

        this.bRendering = true;

        try {
            this.RenderTiles(int1);
        } catch (Exception exception) {
            this.bRendering = false;
            Logger.getLogger(zombie.GameWindow.class.getName()).log(Level.SEVERE, null, exception);
        }

        this.bRendering = false;
        if (IsoGridSquare.getRecalcLightTime() < 0) {
            IsoGridSquare.setRecalcLightTime(60);
        }

        if (IsoGridSquare.getLightcache() <= 0) {
            IsoGridSquare.setLightcache(90);
        }

        for (int int18 = 0; int18 < this.ObjectList.size(); int18++) {
            IsoMovingObject isoMovingObject = (IsoMovingObject)this.ObjectList.get(int18);
            isoMovingObject.renderlast();
        }

        for (int int19 = 0; int19 < this.StaticUpdaterObjectList.size(); int19++) {
            IsoObject isoObject = (IsoObject)this.StaticUpdaterObjectList.get(int19);
            isoObject.renderlast();
        }

        IsoTree.renderChopTreeIndicators();
        if (Core.bDebug) {
        }

        this.lastMinX = this.minX;
        this.lastMinY = this.minY;
        this.DoBuilding(IsoPlayer.getPlayerIndex(), true);
        this.renderRain();
    }

    public void invalidatePeekedRoom(int playerIndex) {
        this.lastPlayerDir[playerIndex] = IsoDirections.Max;
    }

    private boolean initWeatherFx() {
        if (GameServer.bServer) {
            return false;
        } else {
            if (this.weatherFX == null) {
                this.weatherFX = new IsoWeatherFX();
                this.weatherFX.init();
            }

            return true;
        }
    }

    private void updateWeatherFx() {
        if (this.initWeatherFx()) {
            this.weatherFX.update();
        }
    }

    private void renderWeatherFx() {
        if (this.initWeatherFx()) {
            this.weatherFX.render();
        }
    }

    public IsoWeatherFX getWeatherFX() {
        return this.weatherFX;
    }

    private void renderRain() {
    }

    public void setRainAlpha(int alpha) {
        this.rainAlphaMax = (float)alpha / 100.0F;
    }

    public void setRainIntensity(int intensity) {
        this.rainIntensity = intensity;
    }

    public void setRainSpeed(int speed) {
        this.rainSpeed = speed;
    }

    public void reloadRainTextures() {
    }

    private void GetBuildingsInFrontOfCharacter(ArrayList<IsoBuilding> arrayList, IsoGridSquare isoGridSquare, boolean _boolean) {
        arrayList.clear();
        this.bOccludedByOrphanStructureFlag = false;
        if (isoGridSquare != null) {
            int int0 = isoGridSquare.getX();
            int int1 = isoGridSquare.getY();
            int int2 = isoGridSquare.getZ();
            this.GetBuildingsInFrontOfCharacterSquare(int0, int1, int2, _boolean, arrayList);
            if (int2 < MaxHeight) {
                this.GetBuildingsInFrontOfCharacterSquare(int0 - 1 + 3, int1 - 1 + 3, int2 + 1, _boolean, arrayList);
                this.GetBuildingsInFrontOfCharacterSquare(int0 - 2 + 3, int1 - 2 + 3, int2 + 1, _boolean, arrayList);
                if (_boolean) {
                    this.GetBuildingsInFrontOfCharacterSquare(int0 + 3, int1 - 1 + 3, int2 + 1, !_boolean, arrayList);
                    this.GetBuildingsInFrontOfCharacterSquare(int0 - 1 + 3, int1 - 2 + 3, int2 + 1, !_boolean, arrayList);
                } else {
                    this.GetBuildingsInFrontOfCharacterSquare(int0 - 1 + 3, int1 + 3, int2 + 1, !_boolean, arrayList);
                    this.GetBuildingsInFrontOfCharacterSquare(int0 - 2 + 3, int1 - 1 + 3, int2 + 1, !_boolean, arrayList);
                }
            }
        }
    }

    private void GetBuildingsInFrontOfCharacterSquare(int int0, int int1, int int2, boolean _boolean, ArrayList<IsoBuilding> arrayList0) {
        IsoGridSquare isoGridSquare = this.getGridSquare(int0, int1, int2);
        if (isoGridSquare == null) {
            if (int2 < MaxHeight) {
                this.GetBuildingsInFrontOfCharacterSquare(int0 + 3, int1 + 3, int2 + 1, _boolean, arrayList0);
            }
        } else {
            IsoGridOcclusionData isoGridOcclusionData = isoGridSquare.getOrCreateOcclusionData();
            IsoGridOcclusionData.OcclusionFilter occlusionFilter = _boolean
                ? IsoGridOcclusionData.OcclusionFilter.Right
                : IsoGridOcclusionData.OcclusionFilter.Left;
            this.bOccludedByOrphanStructureFlag = this.bOccludedByOrphanStructureFlag
                | isoGridOcclusionData.getCouldBeOccludedByOrphanStructures(occlusionFilter);
            ArrayList arrayList1 = isoGridOcclusionData.getBuildingsCouldBeOccluders(occlusionFilter);

            for (int int3 = 0; int3 < arrayList1.size(); int3++) {
                this.AddUniqueToBuildingList(arrayList0, (IsoBuilding)arrayList1.get(int3));
            }
        }
    }

    private ArrayList<IsoBuilding> GetBuildingsInFrontOfMustSeeSquare(IsoGridSquare isoGridSquare, IsoGridOcclusionData.OcclusionFilter occlusionFilter) {
        IsoGridOcclusionData isoGridOcclusionData = isoGridSquare.getOrCreateOcclusionData();
        this.bOccludedByOrphanStructureFlag = isoGridOcclusionData.getCouldBeOccludedByOrphanStructures(IsoGridOcclusionData.OcclusionFilter.All);
        return isoGridOcclusionData.getBuildingsCouldBeOccluders(occlusionFilter);
    }

    private IsoBuilding GetPeekedInBuilding(IsoGridSquare isoGridSquare0, IsoDirections isoDirections) {
        this.playerPeekedRoomId = -1;
        if (isoGridSquare0 == null) {
            return null;
        } else {
            if ((isoDirections == IsoDirections.NW || isoDirections == IsoDirections.N || isoDirections == IsoDirections.NE)
                && LosUtil.lineClear(
                        this, isoGridSquare0.x, isoGridSquare0.y, isoGridSquare0.z, isoGridSquare0.x, isoGridSquare0.y - 1, isoGridSquare0.z, false
                    )
                    != LosUtil.TestResults.Blocked) {
                IsoGridSquare isoGridSquare1 = isoGridSquare0.nav[IsoDirections.N.index()];
                if (isoGridSquare1 != null) {
                    IsoBuilding isoBuilding0 = isoGridSquare1.getBuilding();
                    if (isoBuilding0 != null) {
                        this.playerPeekedRoomId = isoGridSquare1.getRoomID();
                        return isoBuilding0;
                    }
                }
            }

            if ((isoDirections == IsoDirections.SW || isoDirections == IsoDirections.W || isoDirections == IsoDirections.NW)
                && LosUtil.lineClear(
                        this, isoGridSquare0.x, isoGridSquare0.y, isoGridSquare0.z, isoGridSquare0.x - 1, isoGridSquare0.y, isoGridSquare0.z, false
                    )
                    != LosUtil.TestResults.Blocked) {
                IsoGridSquare isoGridSquare2 = isoGridSquare0.nav[IsoDirections.W.index()];
                if (isoGridSquare2 != null) {
                    IsoBuilding isoBuilding1 = isoGridSquare2.getBuilding();
                    if (isoBuilding1 != null) {
                        this.playerPeekedRoomId = isoGridSquare2.getRoomID();
                        return isoBuilding1;
                    }
                }
            }

            if ((isoDirections == IsoDirections.SE || isoDirections == IsoDirections.S || isoDirections == IsoDirections.SW)
                && LosUtil.lineClear(
                        this, isoGridSquare0.x, isoGridSquare0.y, isoGridSquare0.z, isoGridSquare0.x, isoGridSquare0.y + 1, isoGridSquare0.z, false
                    )
                    != LosUtil.TestResults.Blocked) {
                IsoGridSquare isoGridSquare3 = isoGridSquare0.nav[IsoDirections.S.index()];
                if (isoGridSquare3 != null) {
                    IsoBuilding isoBuilding2 = isoGridSquare3.getBuilding();
                    if (isoBuilding2 != null) {
                        this.playerPeekedRoomId = isoGridSquare3.getRoomID();
                        return isoBuilding2;
                    }
                }
            }

            if ((isoDirections == IsoDirections.NE || isoDirections == IsoDirections.E || isoDirections == IsoDirections.SE)
                && LosUtil.lineClear(
                        this, isoGridSquare0.x, isoGridSquare0.y, isoGridSquare0.z, isoGridSquare0.x + 1, isoGridSquare0.y, isoGridSquare0.z, false
                    )
                    != LosUtil.TestResults.Blocked) {
                IsoGridSquare isoGridSquare4 = isoGridSquare0.nav[IsoDirections.E.index()];
                if (isoGridSquare4 != null) {
                    IsoBuilding isoBuilding3 = isoGridSquare4.getBuilding();
                    if (isoBuilding3 != null) {
                        this.playerPeekedRoomId = isoGridSquare4.getRoomID();
                        return isoBuilding3;
                    }
                }
            }

            return null;
        }
    }

    void GetSquaresAroundPlayerSquare(
        IsoPlayer isoPlayer, IsoGridSquare isoGridSquare0, ArrayList<IsoGridSquare> arrayList0, ArrayList<IsoGridSquare> arrayList1
    ) {
        float float0 = isoPlayer.x - 4.0F;
        float float1 = isoPlayer.y - 4.0F;
        int int0 = (int)float0;
        int int1 = (int)float1;
        int int2 = isoGridSquare0.getZ();

        for (int int3 = int1; int3 < int1 + 10; int3++) {
            for (int int4 = int0; int4 < int0 + 10; int4++) {
                if ((int4 >= (int)isoPlayer.x || int3 >= (int)isoPlayer.y) && (int4 != (int)isoPlayer.x || int3 != (int)isoPlayer.y)) {
                    float float2 = (float)int4 - isoPlayer.x;
                    float float3 = (float)int3 - isoPlayer.y;
                    if ((double)float3 < (double)float2 + 4.5 && (double)float3 > (double)float2 - 4.5) {
                        IsoGridSquare isoGridSquare1 = this.getGridSquare(int4, int3, int2);
                        if (isoGridSquare1 != null) {
                            if (float3 >= float2) {
                                arrayList0.add(isoGridSquare1);
                            }

                            if (float3 <= float2) {
                                arrayList1.add(isoGridSquare1);
                            }
                        }
                    }
                }
            }
        }
    }

    private boolean IsBehindStuff(IsoGridSquare isoGridSquare0) {
        if (!isoGridSquare0.getProperties().Is(IsoFlagType.exterior)) {
            return true;
        } else {
            for (int int0 = 1; int0 < 8 && isoGridSquare0.getZ() + int0 < MaxHeight; int0++) {
                for (int int1 = -5; int1 <= 6; int1++) {
                    for (int int2 = -5; int2 <= 6; int2++) {
                        if (int2 >= int1 - 5 && int2 <= int1 + 5) {
                            IsoGridSquare isoGridSquare1 = this.getGridSquare(
                                isoGridSquare0.getX() + int2 + int0 * 3, isoGridSquare0.getY() + int1 + int0 * 3, isoGridSquare0.getZ() + int0
                            );
                            if (isoGridSquare1 != null && !isoGridSquare1.getObjects().isEmpty()) {
                                if (int0 != 1 || isoGridSquare1.getObjects().size() != 1) {
                                    return true;
                                }

                                IsoObject isoObject = isoGridSquare1.getObjects().get(0);
                                if (isoObject.sprite == null || isoObject.sprite.name == null || !isoObject.sprite.name.startsWith("lighting_outdoor")) {
                                    return true;
                                }
                            }
                        }
                    }
                }
            }

            return false;
        }
    }

    public static IsoDirections FromMouseTile() {
        IsoDirections isoDirections = IsoDirections.N;
        float float0 = UIManager.getPickedTileLocal().x;
        float float1 = UIManager.getPickedTileLocal().y;
        float float2 = 0.5F - Math.abs(0.5F - float1);
        float float3 = 0.5F - Math.abs(0.5F - float0);
        if (float0 > 0.5F && float3 < float2) {
            isoDirections = IsoDirections.E;
        } else if (float1 > 0.5F && float3 > float2) {
            isoDirections = IsoDirections.S;
        } else if (float0 < 0.5F && float3 < float2) {
            isoDirections = IsoDirections.W;
        } else if (float1 < 0.5F && float3 > float2) {
            isoDirections = IsoDirections.N;
        }

        return isoDirections;
    }

    public void update() {
        IsoCell.s_performance.isoCellUpdate.invokeAndMeasure(this, IsoCell::updateInternal);
    }

    private void updateInternal() {
        zombie.MovingObjectUpdateScheduler.instance.startFrame();
        IsoSprite.alphaStep = 0.075F * (zombie.GameTime.getInstance().getMultiplier() / 1.6F);
        IsoGridSquare.gridSquareCacheEmptyTimer++;
        this.ProcessSpottedRooms();
        if (!GameServer.bServer) {
            for (int _int = 0; _int < IsoPlayer.numPlayers; _int++) {
                if (IsoPlayer.players[_int] != null && (!IsoPlayer.players[_int].isDead() || IsoPlayer.players[_int].ReanimatedCorpse != null)) {
                    IsoPlayer.setInstance(IsoPlayer.players[_int]);
                    IsoCamera.CamCharacter = IsoPlayer.players[_int];
                    this.ChunkMap[_int].update();
                }
            }
        }

        this.ProcessRemoveItems(null);
        this.ProcessItems(null);
        this.ProcessRemoveItems(null);
        this.ProcessIsoObject();
        this.safeToAdd = false;
        this.ProcessObjects(null);
        if (GameClient.bClient
            && (
                NetworkZombieSimulator.getInstance().anyUnknownZombies() && GameClient.instance.sendZombieRequestsTimer.Check()
                    || GameClient.instance.sendZombieTimer.Check()
            )) {
            NetworkZombieSimulator.getInstance().send();
            GameClient.instance.sendZombieTimer.Reset();
            GameClient.instance.sendZombieRequestsTimer.Reset();
        }

        this.safeToAdd = true;
        this.ProcessStaticUpdaters();
        this.ObjectDeletionAddition();
        IsoDeadBody.updateBodies();
        IsoGridSquare.setLightcache(IsoGridSquare.getLightcache() - 1);
        IsoGridSquare.setRecalcLightTime(IsoGridSquare.getRecalcLightTime() - 1);
        if (GameServer.bServer) {
            this.LamppostPositions.clear();
            this.roomLights.clear();
        }

        if (!zombie.GameTime.isGamePaused()) {
            this.rainScroll = this.rainScroll + (float)this.rainSpeed / 10.0F * 0.075F * (30.0F / (float)PerformanceSettings.getLockFPS());
            if (this.rainScroll > 1.0F) {
                this.rainScroll = 0.0F;
            }
        }

        if (!GameServer.bServer) {
            this.updateWeatherFx();
        }
    }

    IsoGridSquare getRandomFreeTile() {
        IsoGridSquare isoGridSquare = null;
        boolean _boolean = true;

        do {
            _boolean = true;
            isoGridSquare = this.getGridSquare(Rand.Next(this.width), Rand.Next(this.height), 0);
            if (isoGridSquare == null) {
                _boolean = false;
            } else if (!isoGridSquare.isFree(false)) {
                _boolean = false;
            } else if (isoGridSquare.getProperties().Is(IsoFlagType.solid) || isoGridSquare.getProperties().Is(IsoFlagType.solidtrans)) {
                _boolean = false;
            } else if (isoGridSquare.getMovingObjects().size() > 0) {
                _boolean = false;
            } else if (isoGridSquare.Has(IsoObjectType.stairsBN) || isoGridSquare.Has(IsoObjectType.stairsMN) || isoGridSquare.Has(IsoObjectType.stairsTN)) {
                _boolean = false;
            } else if (isoGridSquare.Has(IsoObjectType.stairsBW) || isoGridSquare.Has(IsoObjectType.stairsMW) || isoGridSquare.Has(IsoObjectType.stairsTW)) {
                _boolean = false;
            }
        } while (!_boolean);

        return isoGridSquare;
    }

    IsoGridSquare getRandomOutdoorFreeTile() {
        IsoGridSquare isoGridSquare = null;
        boolean _boolean = true;

        do {
            _boolean = true;
            isoGridSquare = this.getGridSquare(Rand.Next(this.width), Rand.Next(this.height), 0);
            if (isoGridSquare == null) {
                _boolean = false;
            } else if (!isoGridSquare.isFree(false)) {
                _boolean = false;
            } else if (isoGridSquare.getRoom() != null) {
                _boolean = false;
            } else if (isoGridSquare.getProperties().Is(IsoFlagType.solid) || isoGridSquare.getProperties().Is(IsoFlagType.solidtrans)) {
                _boolean = false;
            } else if (isoGridSquare.getMovingObjects().size() > 0) {
                _boolean = false;
            } else if (isoGridSquare.Has(IsoObjectType.stairsBN) || isoGridSquare.Has(IsoObjectType.stairsMN) || isoGridSquare.Has(IsoObjectType.stairsTN)) {
                _boolean = false;
            } else if (isoGridSquare.Has(IsoObjectType.stairsBW) || isoGridSquare.Has(IsoObjectType.stairsMW) || isoGridSquare.Has(IsoObjectType.stairsTW)) {
                _boolean = false;
            }
        } while (!_boolean);

        return isoGridSquare;
    }

    public IsoGridSquare getRandomFreeTileInRoom() {
        Stack stack = new Stack();

        for (int _int = 0; _int < this.RoomList.size(); _int++) {
            if (((IsoRoom)this.RoomList.get(_int)).TileList.size() > 9
                && !((IsoRoom)this.RoomList.get(_int)).Exits.isEmpty()
                && ((IsoGridSquare)((IsoRoom)this.RoomList.get(_int)).TileList.get(0)).getProperties().Is(IsoFlagType.solidfloor)) {
                stack.add((IsoRoom)this.RoomList.get(_int));
            }
        }

        if (stack.isEmpty()) {
            return null;
        } else {
            IsoRoom isoRoom = (IsoRoom)stack.get(Rand.Next(stack.size()));
            return isoRoom.getFreeTile();
        }
    }

    public void roomSpotted(IsoRoom room) {
        synchronized (this.SpottedRooms) {
            if (!this.SpottedRooms.contains(room)) {
                this.SpottedRooms.push(room);
            }
        }
    }

    public void ProcessSpottedRooms() {
        synchronized (this.SpottedRooms) {
            for (int _int = 0; _int < this.SpottedRooms.size(); _int++) {
                IsoRoom isoRoom = (IsoRoom)this.SpottedRooms.get(_int);
                if (!isoRoom.def.bDoneSpawn) {
                    isoRoom.def.bDoneSpawn = true;
                    LuaEventManager.triggerEvent("OnSeeNewRoom", isoRoom);
                    zombie.VirtualZombieManager.instance.roomSpotted(isoRoom);
                    if (!GameClient.bClient
                        && !Core.bLastStand
                        && ("shed".equals(isoRoom.def.name) || "garagestorage".equals(isoRoom.def.name) || "storageunit".equals(isoRoom.def.name))) {
                        byte _byte = 7;
                        if ("shed".equals(isoRoom.def.name) || "garagestorage".equals(isoRoom.def.name)) {
                            _byte = 4;
                        }

                        switch (zombie.SandboxOptions.instance.GeneratorSpawning.getValue()) {
                            case 1:
                                _byte += 3;
                                break;
                            case 2:
                                _byte += 2;
                            case 3:
                            default:
                                break;
                            case 4:
                                _byte -= 2;
                                break;
                            case 5:
                                _byte -= 3;
                        }

                        if (Rand.Next(_byte) == 0) {
                            IsoGridSquare isoGridSquare = isoRoom.getRandomFreeSquare();
                            if (isoGridSquare != null) {
                                IsoGenerator isoGenerator = new IsoGenerator(InventoryItemFactory.CreateItem("Base.Generator"), this, isoGridSquare);
                                if (GameServer.bServer) {
                                    isoGenerator.transmitCompleteItemToClients();
                                }
                            }
                        }
                    }
                }
            }

            this.SpottedRooms.clear();
        }
    }

    public void savePlayer() throws IOException {
        if (IsoPlayer.players[0] != null && !IsoPlayer.players[0].isDead()) {
            IsoPlayer.players[0].save();
        }

        GameClient.instance.sendPlayerSave(IsoPlayer.players[0]);
    }

    public void save(DataOutputStream output, boolean bDoChars) throws IOException {
        while (ChunkSaveWorker.instance.bSaving) {
            try {
                Thread.sleep(30L);
            } catch (InterruptedException interruptedException) {
                interruptedException.printStackTrace();
            }
        }

        for (int _int = 0; _int < IsoPlayer.numPlayers; _int++) {
            this.ChunkMap[_int].Save();
        }

        output.writeInt(this.width);
        output.writeInt(this.height);
        output.writeInt(MaxHeight);
        File file = zombie.ZomboidFileSystem.instance.getFileInCurrentSave("map_t.bin");
        FileOutputStream fileOutputStream = new FileOutputStream(file);
        output = new DataOutputStream(new BufferedOutputStream(fileOutputStream));
        zombie.GameTime.instance.save(output);
        output.flush();
        output.close();
        IsoWorld.instance.MetaGrid.save();
        if (PlayerDB.isAllow()) {
            PlayerDB.getInstance().savePlayers();
        }

        zombie.ReanimatedPlayers.instance.saveReanimatedPlayers();
    }

    public boolean LoadPlayer(int WorldVersion) throws FileNotFoundException, IOException {
        if (GameClient.bClient) {
            return ClientPlayerDB.getInstance().loadNetworkPlayer();
        } else {
            File file = zombie.ZomboidFileSystem.instance.getFileInCurrentSave("map_p.bin");
            if (!file.exists()) {
                PlayerDB.getInstance().importPlayersFromVehiclesDB();
                return PlayerDB.getInstance().loadLocalPlayer(1);
            } else {
                FileInputStream fileInputStream = new FileInputStream(file);
                BufferedInputStream bufferedInputStream = new BufferedInputStream(fileInputStream);
                synchronized (SliceY.SliceBufferLock) {
                    SliceY.SliceBuffer.clear();
                    int _int = bufferedInputStream.read(SliceY.SliceBuffer.array());
                    SliceY.SliceBuffer.limit(_int);
                    byte byte0 = SliceY.SliceBuffer.get();
                    byte byte1 = SliceY.SliceBuffer.get();
                    byte byte2 = SliceY.SliceBuffer.get();
                    byte byte3 = SliceY.SliceBuffer.get();
                    if (byte0 == 80 && byte1 == 76 && byte2 == 89 && byte3 == 82) {
                        WorldVersion = SliceY.SliceBuffer.getInt();
                    } else {
                        SliceY.SliceBuffer.rewind();
                    }

                    if (WorldVersion >= 69) {
                        String string = zombie.GameWindow.ReadString(SliceY.SliceBuffer);
                        if (GameClient.bClient && WorldVersion < 71) {
                            string = ServerOptions.instance.ServerPlayerID.getValue();
                        }

                        if (GameClient.bClient && !IsoPlayer.isServerPlayerIDValid(string)) {
                            GameLoadingState.GameLoadingString = Translator.getText("IGUI_MP_ServerPlayerIDMismatch");
                            GameLoadingState.playerWrongIP = true;
                            return false;
                        }
                    }

                    instance.ChunkMap[IsoPlayer.getPlayerIndex()].WorldX = SliceY.SliceBuffer.getInt() + IsoWorld.saveoffsetx * 30;
                    instance.ChunkMap[IsoPlayer.getPlayerIndex()].WorldY = SliceY.SliceBuffer.getInt() + IsoWorld.saveoffsety * 30;
                    SliceY.SliceBuffer.getInt();
                    SliceY.SliceBuffer.getInt();
                    SliceY.SliceBuffer.getInt();
                    if (IsoPlayer.getInstance() == null) {
                        IsoPlayer.setInstance(new IsoPlayer(instance));
                        IsoPlayer.players[0] = IsoPlayer.getInstance();
                    }

                    IsoPlayer.getInstance().load(SliceY.SliceBuffer, WorldVersion);
                    fileInputStream.close();
                }

                PlayerDB.getInstance().saveLocalPlayersForce();
                file.delete();
                PlayerDB.getInstance().uploadLocalPlayers2DB();
                return true;
            }
        }
    }

    public IsoGridSquare getRelativeGridSquare(int x, int y, int z) {
        int int0 = this.ChunkMap[0].getWorldXMin();
        IsoChunkMap isoChunkMap = this.ChunkMap[0];
        int int1 = int0 * 10;
        int0 = this.ChunkMap[0].getWorldYMin();
        isoChunkMap = this.ChunkMap[0];
        int int2 = int0 * 10;
        x += int1;
        y += int2;
        return this.getGridSquare(x, y, z);
    }

    public IsoGridSquare createNewGridSquare(int x, int y, int z, boolean recalcAll) {
        if (!IsoWorld.instance.isValidSquare(x, y, z)) {
            return null;
        } else {
            IsoGridSquare isoGridSquare = this.getGridSquare(x, y, z);
            if (isoGridSquare != null) {
                return isoGridSquare;
            } else {
                if (GameServer.bServer) {
                    int int0 = x / 10;
                    int int1 = y / 10;
                    if (ServerMap.instance.getChunk(int0, int1) != null) {
                        isoGridSquare = IsoGridSquare.getNew(this, null, x, y, z);
                        ServerMap.instance.setGridSquare(x, y, z, isoGridSquare);
                    }
                } else if (this.getChunkForGridSquare(x, y, z) != null) {
                    isoGridSquare = IsoGridSquare.getNew(this, null, x, y, z);
                    this.ConnectNewSquare(isoGridSquare, true);
                }

                if (isoGridSquare != null && recalcAll) {
                    isoGridSquare.RecalcAllWithNeighbours(true);
                }

                return isoGridSquare;
            }
        }
    }

    public IsoGridSquare getGridSquareDirect(int x, int y, int z, int playerIndex) {
        int _int = IsoChunkMap.ChunkWidthInTiles;
        return this.gridSquares[playerIndex][x + y * _int + z * _int * _int];
    }

    public boolean isInChunkMap(int x, int y) {
        for (int int0 = 0; int0 < IsoPlayer.numPlayers; int0++) {
            int int1 = this.ChunkMap[int0].getWorldXMinTiles();
            int int2 = this.ChunkMap[int0].getWorldXMaxTiles();
            int int3 = this.ChunkMap[int0].getWorldYMinTiles();
            int int4 = this.ChunkMap[int0].getWorldYMaxTiles();
            if (x >= int1 && x < int2 && y >= int3 && y < int4) {
                return true;
            }
        }

        return false;
    }

    public ArrayList<IsoObject> getProcessIsoObjectRemove() {
        return this.ProcessIsoObjectRemove;
    }

    public void checkHaveRoof(int x, int y) {
        boolean _boolean = false;

        for (int _int = 8; _int >= 0; _int--) {
            IsoGridSquare isoGridSquare = this.getGridSquare(x, y, _int);
            if (isoGridSquare != null) {
                if (_boolean != isoGridSquare.haveRoof) {
                    isoGridSquare.haveRoof = _boolean;
                    isoGridSquare.RecalcAllWithNeighbours(true);
                }

                if (isoGridSquare.Is(IsoFlagType.solidfloor)) {
                    _boolean = true;
                }
            }
        }
    }

    public IsoZombie getFakeZombieForHit() {
        if (this.fakeZombieForHit == null) {
            this.fakeZombieForHit = new IsoZombie(this);
        }

        return this.fakeZombieForHit;
    }

    public void addHeatSource(IsoHeatSource heatSource) {
        if (!GameServer.bServer) {
            if (this.heatSources.contains(heatSource)) {
                DebugLog.log("ERROR addHeatSource called again with the same HeatSource");
            } else {
                this.heatSources.add(heatSource);
            }
        }
    }

    public void removeHeatSource(IsoHeatSource heatSource) {
        if (!GameServer.bServer) {
            this.heatSources.remove(heatSource);
        }
    }

    public void updateHeatSources() {
        if (!GameServer.bServer) {
            for (int _int = this.heatSources.size() - 1; _int >= 0; _int--) {
                IsoHeatSource isoHeatSource = (IsoHeatSource)this.heatSources.get(_int);
                if (!isoHeatSource.isInBounds()) {
                    this.heatSources.remove(_int);
                }
            }
        }
    }

    public int getHeatSourceTemperature(int x, int y, int z) {
        int int0 = 0;

        for (int int1 = 0; int1 < this.heatSources.size(); int1++) {
            IsoHeatSource isoHeatSource = (IsoHeatSource)this.heatSources.get(int1);
            if (isoHeatSource.getZ() == z) {
                float _float = IsoUtils.DistanceToSquared((float)x, (float)y, (float)isoHeatSource.getX(), (float)isoHeatSource.getY());
                if (_float < (float)(isoHeatSource.getRadius() * isoHeatSource.getRadius())) {
                    LosUtil.TestResults testResults = LosUtil.lineClear(this, isoHeatSource.getX(), isoHeatSource.getY(), isoHeatSource.getZ(), x, y, z, false);
                    if (testResults == LosUtil.TestResults.Clear || testResults == LosUtil.TestResults.ClearThroughOpenDoor) {
                        int0 = (int)(
                            (double)int0 + (double)isoHeatSource.getTemperature() * (1.0 - Math.sqrt((double)_float) / (double)isoHeatSource.getRadius())
                        );
                    }
                }
            }
        }

        return int0;
    }

    public float getHeatSourceHighestTemperature(float surroundingAirTemperature, int x, int y, int z) {
        float float0 = surroundingAirTemperature;
        float float1 = surroundingAirTemperature;
        float float2 = 0.0F;
        Object object = null;
        float float3 = 0.0F;

        for (int _int = 0; _int < this.heatSources.size(); _int++) {
            IsoHeatSource isoHeatSource = (IsoHeatSource)this.heatSources.get(_int);
            if (isoHeatSource.getZ() == z) {
                float float4 = IsoUtils.DistanceToSquared((float)x, (float)y, (float)isoHeatSource.getX(), (float)isoHeatSource.getY());
                object = this.getGridSquare(isoHeatSource.getX(), isoHeatSource.getY(), isoHeatSource.getZ());
                float3 = 0.0F;
                if (object != null) {
                    if (!((IsoGridSquare)object).isInARoom()) {
                        float3 = float0 - 30.0F;
                        if (float3 < -15.0F) {
                            float3 = -15.0F;
                        } else if (float3 > 5.0F) {
                            float3 = 5.0F;
                        }
                    } else {
                        float3 = float0 - 30.0F;
                        if (float3 < -7.0F) {
                            float3 = -7.0F;
                        } else if (float3 > 7.0F) {
                            float3 = 7.0F;
                        }
                    }
                }

                float2 = ClimateManager.lerp(
                    (float)(1.0 - Math.sqrt((double)float4) / (double)isoHeatSource.getRadius()), float0, (float)isoHeatSource.getTemperature() + float3
                );
                if (!(float2 <= float1) && float4 < (float)(isoHeatSource.getRadius() * isoHeatSource.getRadius())) {
                    LosUtil.TestResults testResults = LosUtil.lineClear(this, isoHeatSource.getX(), isoHeatSource.getY(), isoHeatSource.getZ(), x, y, z, false);
                    if (testResults == LosUtil.TestResults.Clear || testResults == LosUtil.TestResults.ClearThroughOpenDoor) {
                        float1 = float2;
                    }
                }
            }
        }

        return float1;
    }

    public void putInVehicle(IsoGameCharacter chr) {
        if (chr != null && chr.savedVehicleSeat != -1) {
            int int0 = ((int)chr.getX() - 4) / 10;
            int int1 = ((int)chr.getY() - 4) / 10;
            int int2 = ((int)chr.getX() + 4) / 10;
            int int3 = ((int)chr.getY() + 4) / 10;

            for (int int4 = int1; int4 <= int3; int4++) {
                for (int int5 = int0; int5 <= int2; int5++) {
                    IsoChunk isoChunk = this.getChunkForGridSquare(int5 * 10, int4 * 10, (int)chr.getZ());
                    if (isoChunk != null) {
                        for (int int6 = 0; int6 < isoChunk.vehicles.size(); int6++) {
                            BaseVehicle baseVehicle = (BaseVehicle)isoChunk.vehicles.get(int6);
                            if ((int)baseVehicle.getZ() == (int)chr.getZ()
                                && IsoUtils.DistanceToSquared(baseVehicle.getX(), baseVehicle.getY(), chr.savedVehicleX, chr.savedVehicleY) < 0.010000001F) {
                                if (baseVehicle.VehicleID == -1) {
                                    return;
                                }

                                VehicleScript.Position position = baseVehicle.getPassengerPosition(chr.savedVehicleSeat, "inside");
                                if (position != null && !baseVehicle.isSeatOccupied(chr.savedVehicleSeat)) {
                                    baseVehicle.enter(chr.savedVehicleSeat, chr, position.offset);
                                    LuaEventManager.triggerEvent("OnEnterVehicle", chr);
                                    if (baseVehicle.getCharacter(chr.savedVehicleSeat) == chr && chr.savedVehicleRunning) {
                                        baseVehicle.resumeRunningAfterLoad();
                                    }
                                }

                                return;
                            }
                        }
                    }
                }
            }
        }
    }

    @Deprecated
    public void resumeVehicleSounds(IsoGameCharacter chr) {
        if (chr != null && chr.savedVehicleSeat != -1) {
            int int0 = ((int)chr.getX() - 4) / 10;
            int int1 = ((int)chr.getY() - 4) / 10;
            int int2 = ((int)chr.getX() + 4) / 10;
            int int3 = ((int)chr.getY() + 4) / 10;

            for (int int4 = int1; int4 <= int3; int4++) {
                for (int int5 = int0; int5 <= int2; int5++) {
                    IsoChunk isoChunk = this.getChunkForGridSquare(int5 * 10, int4 * 10, (int)chr.getZ());
                    if (isoChunk != null) {
                        for (int int6 = 0; int6 < isoChunk.vehicles.size(); int6++) {
                            BaseVehicle baseVehicle = (BaseVehicle)isoChunk.vehicles.get(int6);
                            if (baseVehicle.lightbarSirenMode.isEnable()) {
                                baseVehicle.setLightbarSirenMode(baseVehicle.lightbarSirenMode.get());
                            }
                        }
                    }
                }
            }
        }
    }

    private void AddUniqueToBuildingList(ArrayList<IsoBuilding> arrayList, IsoBuilding isoBuilding) {
        for (int _int = 0; _int < arrayList.size(); _int++) {
            if (arrayList.get(_int) == isoBuilding) {
                return;
            }
        }

        arrayList.add(isoBuilding);
    }

    public IsoSpriteManager getSpriteManager() {
        return IsoSpriteManager.instance;
    }

    public static enum BuildingSearchCriteria {
        Food,
        Defense,
        Wood,
        Weapons,
        General;
    }

    public static final class PerPlayerRender {
        public final IsoGridStack GridStacks = new IsoGridStack(9);
        public boolean[][][] VisiOccludedFlags;
        public boolean[][] VisiCulledFlags;
        public short[][][] StencilValues;
        public boolean[][] FlattenGrassEtc;
        public int minX;
        public int minY;
        public int maxX;
        public int maxY;

        public void setSize(int w, int h) {
            if (this.VisiOccludedFlags == null || this.VisiOccludedFlags.length < w || this.VisiOccludedFlags[0].length < h) {
                this.VisiOccludedFlags = new boolean[w][h][2];
                this.VisiCulledFlags = new boolean[w][h];
                this.StencilValues = new short[w][h][2];
                this.FlattenGrassEtc = new boolean[w][h];
            }
        }
    }

    private class SnowGrid {
        public int w = 256;
        public int h = 256;
        public int frac = 0;
        public static final int N = 0;
        public static final int S = 1;
        public static final int W = 2;
        public static final int E = 3;
        public static final int A = 0;
        public static final int B = 1;
        public final Texture[][][] grid = new Texture[this.w][this.h][2];
        public final byte[][][] gridType = new byte[this.w][this.h][2];

        public SnowGrid(int _int) {
            this.init(_int);
        }

        public IsoCell.SnowGrid init(int int9) {
            if (!IsoCell.this.hasSetupSnowGrid) {
                IsoCell.this.snowNoise2D = new Noise2D();
                IsoCell.this.snowNoise2D.addLayer(16, 0.5F, 3.0F);
                IsoCell.this.snowNoise2D.addLayer(32, 2.0F, 5.0F);
                IsoCell.this.snowNoise2D.addLayer(64, 5.0F, 8.0F);
                byte byte0 = 0;
                IsoCell.this.snowGridTiles_Square = IsoCell.this.new SnowGridTiles(byte0++);
                byte byte1 = 40;

                for (int int0 = 0; int0 < 4; int0++) {
                    IsoCell.this.snowGridTiles_Square.add(Texture.getSharedTexture("e_newsnow_ground_1_" + (byte1 + int0)));
                }

                IsoCell.this.snowGridTiles_Enclosed = IsoCell.this.new SnowGridTiles(byte0++);
                byte1 = 0;

                for (int int1 = 0; int1 < 4; int1++) {
                    IsoCell.this.snowGridTiles_Enclosed.add(Texture.getSharedTexture("e_newsnow_ground_1_" + (byte1 + int1)));
                }

                IsoCell.this.snowGridTiles_Cove = new IsoCell.SnowGridTiles[4];

                for (int int2 = 0; int2 < 4; int2++) {
                    IsoCell.this.snowGridTiles_Cove[int2] = IsoCell.this.new SnowGridTiles(byte0++);
                    if (int2 == 0) {
                        byte1 = 7;
                    }

                    if (int2 == 2) {
                        byte1 = 4;
                    }

                    if (int2 == 1) {
                        byte1 = 5;
                    }

                    if (int2 == 3) {
                        byte1 = 6;
                    }

                    for (int int3 = 0; int3 < 3; int3++) {
                        IsoCell.this.snowGridTiles_Cove[int2].add(Texture.getSharedTexture("e_newsnow_ground_1_" + (byte1 + int3 * 4)));
                    }
                }

                IsoCell.this.m_snowFirstNonSquare = byte0;
                IsoCell.this.snowGridTiles_Edge = new IsoCell.SnowGridTiles[4];

                for (int int4 = 0; int4 < 4; int4++) {
                    IsoCell.this.snowGridTiles_Edge[int4] = IsoCell.this.new SnowGridTiles(byte0++);
                    if (int4 == 0) {
                        byte1 = 16;
                    }

                    if (int4 == 2) {
                        byte1 = 18;
                    }

                    if (int4 == 1) {
                        byte1 = 17;
                    }

                    if (int4 == 3) {
                        byte1 = 19;
                    }

                    for (int int5 = 0; int5 < 3; int5++) {
                        IsoCell.this.snowGridTiles_Edge[int4].add(Texture.getSharedTexture("e_newsnow_ground_1_" + (byte1 + int5 * 4)));
                    }
                }

                IsoCell.this.snowGridTiles_Strip = new IsoCell.SnowGridTiles[4];

                for (int int6 = 0; int6 < 4; int6++) {
                    IsoCell.this.snowGridTiles_Strip[int6] = IsoCell.this.new SnowGridTiles(byte0++);
                    if (int6 == 0) {
                        byte1 = 28;
                    }

                    if (int6 == 2) {
                        byte1 = 29;
                    }

                    if (int6 == 1) {
                        byte1 = 31;
                    }

                    if (int6 == 3) {
                        byte1 = 30;
                    }

                    for (int int7 = 0; int7 < 3; int7++) {
                        IsoCell.this.snowGridTiles_Strip[int6].add(Texture.getSharedTexture("e_newsnow_ground_1_" + (byte1 + int7 * 4)));
                    }
                }

                IsoCell.this.hasSetupSnowGrid = true;
            }

            IsoCell.this.snowGridTiles_Square.resetCounter();
            IsoCell.this.snowGridTiles_Enclosed.resetCounter();

            for (int int8 = 0; int8 < 4; int8++) {
                IsoCell.this.snowGridTiles_Cove[int8].resetCounter();
                IsoCell.this.snowGridTiles_Edge[int8].resetCounter();
                IsoCell.this.snowGridTiles_Strip[int8].resetCounter();
            }

            this.frac = int9;
            Noise2D noise2D = IsoCell.this.snowNoise2D;

            for (int int10 = 0; int10 < this.h; int10++) {
                for (int int11 = 0; int11 < this.w; int11++) {
                    for (int int12 = 0; int12 < 2; int12++) {
                        this.grid[int11][int10][int12] = null;
                        this.gridType[int11][int10][int12] = -1;
                    }

                    if (noise2D.layeredNoise((float)int11 / 10.0F, (float)int10 / 10.0F) <= (float)int9 / 100.0F) {
                        this.grid[int11][int10][0] = IsoCell.this.snowGridTiles_Square.getNext();
                        this.gridType[int11][int10][0] = IsoCell.this.snowGridTiles_Square.ID;
                    }
                }
            }

            for (int int13 = 0; int13 < this.h; int13++) {
                for (int int14 = 0; int14 < this.w; int14++) {
                    Texture texture = this.grid[int14][int13][0];
                    if (texture == null) {
                        boolean boolean0 = this.check(int14, int13 - 1);
                        boolean boolean1 = this.check(int14, int13 + 1);
                        boolean boolean2 = this.check(int14 - 1, int13);
                        boolean boolean3 = this.check(int14 + 1, int13);
                        int int15 = 0;
                        if (boolean0) {
                            int15++;
                        }

                        if (boolean1) {
                            int15++;
                        }

                        if (boolean3) {
                            int15++;
                        }

                        if (boolean2) {
                            int15++;
                        }

                        if (int15 != 0) {
                            if (int15 == 1) {
                                if (boolean0) {
                                    this.set(int14, int13, 0, IsoCell.this.snowGridTiles_Strip[0]);
                                } else if (boolean1) {
                                    this.set(int14, int13, 0, IsoCell.this.snowGridTiles_Strip[1]);
                                } else if (boolean3) {
                                    this.set(int14, int13, 0, IsoCell.this.snowGridTiles_Strip[3]);
                                } else if (boolean2) {
                                    this.set(int14, int13, 0, IsoCell.this.snowGridTiles_Strip[2]);
                                }
                            } else if (int15 == 2) {
                                if (boolean0 && boolean1) {
                                    this.set(int14, int13, 0, IsoCell.this.snowGridTiles_Strip[0]);
                                    this.set(int14, int13, 1, IsoCell.this.snowGridTiles_Strip[1]);
                                } else if (boolean3 && boolean2) {
                                    this.set(int14, int13, 0, IsoCell.this.snowGridTiles_Strip[2]);
                                    this.set(int14, int13, 1, IsoCell.this.snowGridTiles_Strip[3]);
                                } else if (boolean0) {
                                    this.set(int14, int13, 0, IsoCell.this.snowGridTiles_Edge[boolean2 ? 0 : 3]);
                                } else if (boolean1) {
                                    this.set(int14, int13, 0, IsoCell.this.snowGridTiles_Edge[boolean2 ? 2 : 1]);
                                } else if (boolean2) {
                                    this.set(int14, int13, 0, IsoCell.this.snowGridTiles_Edge[boolean0 ? 0 : 2]);
                                } else if (boolean3) {
                                    this.set(int14, int13, 0, IsoCell.this.snowGridTiles_Edge[boolean0 ? 3 : 1]);
                                }
                            } else if (int15 == 3) {
                                if (!boolean0) {
                                    this.set(int14, int13, 0, IsoCell.this.snowGridTiles_Cove[1]);
                                } else if (!boolean1) {
                                    this.set(int14, int13, 0, IsoCell.this.snowGridTiles_Cove[0]);
                                } else if (!boolean3) {
                                    this.set(int14, int13, 0, IsoCell.this.snowGridTiles_Cove[2]);
                                } else if (!boolean2) {
                                    this.set(int14, int13, 0, IsoCell.this.snowGridTiles_Cove[3]);
                                }
                            } else if (int15 == 4) {
                                this.set(int14, int13, 0, IsoCell.this.snowGridTiles_Enclosed);
                            }
                        }
                    }
                }
            }

            return this;
        }

        public boolean check(int int0, int int1) {
            if (int0 == this.w) {
                int0 = 0;
            }

            if (int0 == -1) {
                int0 = this.w - 1;
            }

            if (int1 == this.h) {
                int1 = 0;
            }

            if (int1 == -1) {
                int1 = this.h - 1;
            }

            if (int0 < 0 || int0 >= this.w) {
                return false;
            } else if (int1 >= 0 && int1 < this.h) {
                Texture texture = this.grid[int0][int1][0];
                return IsoCell.this.snowGridTiles_Square.contains(texture);
            } else {
                return false;
            }
        }

        public boolean checkAny(int int0, int int1) {
            if (int0 == this.w) {
                int0 = 0;
            }

            if (int0 == -1) {
                int0 = this.w - 1;
            }

            if (int1 == this.h) {
                int1 = 0;
            }

            if (int1 == -1) {
                int1 = this.h - 1;
            }

            if (int0 < 0 || int0 >= this.w) {
                return false;
            } else {
                return int1 >= 0 && int1 < this.h ? this.grid[int0][int1][0] != null : false;
            }
        }

        public void set(int int0, int int1, int int2, IsoCell.SnowGridTiles snowGridTiles) {
            if (int0 == this.w) {
                int0 = 0;
            }

            if (int0 == -1) {
                int0 = this.w - 1;
            }

            if (int1 == this.h) {
                int1 = 0;
            }

            if (int1 == -1) {
                int1 = this.h - 1;
            }

            if (int0 >= 0 && int0 < this.w) {
                if (int1 >= 0 && int1 < this.h) {
                    this.grid[int0][int1][int2] = snowGridTiles.getNext();
                    this.gridType[int0][int1][int2] = snowGridTiles.ID;
                }
            }
        }

        public void subtract(IsoCell.SnowGrid snowGrid1) {
            for (int int0 = 0; int0 < this.h; int0++) {
                for (int int1 = 0; int1 < this.w; int1++) {
                    for (int int2 = 0; int2 < 2; int2++) {
                        if (snowGrid1.gridType[int1][int0][int2] == this.gridType[int1][int0][int2]) {
                            this.grid[int1][int0][int2] = null;
                            this.gridType[int1][int0][int2] = -1;
                        }
                    }
                }
            }
        }
    }

    protected class SnowGridTiles {
        protected byte ID = -1;
        private int counter = -1;
        private final ArrayList<Texture> textures = new ArrayList();

        public SnowGridTiles(byte _byte) {
            this.ID = _byte;
        }

        protected void add(Texture texture) {
            this.textures.add(texture);
        }

        protected Texture getNext() {
            this.counter++;
            if (this.counter >= this.textures.size()) {
                this.counter = 0;
            }

            return (Texture)this.textures.get(this.counter);
        }

        protected Texture get(int _int) {
            return (Texture)this.textures.get(_int);
        }

        protected int size() {
            return this.textures.size();
        }

        protected Texture getRand() {
            return (Texture)this.textures.get(Rand.Next(4));
        }

        protected boolean contains(Texture texture) {
            return this.textures.contains(texture);
        }

        protected void resetCounter() {
            this.counter = 0;
        }
    }

    private static class s_performance {
        static final PerformanceProfileProbe isoCellUpdate = new PerformanceProfileProbe("IsoCell.update");
        static final PerformanceProfileProbe isoCellRender = new PerformanceProfileProbe("IsoCell.render");
        static final PerformanceProfileProbe isoCellRenderTiles = new PerformanceProfileProbe("IsoCell.renderTiles");
        static final PerformanceProfileProbe isoCellDoBuilding = new PerformanceProfileProbe("IsoCell.doBuilding");

        static class renderTiles {
            static final PerformanceProfileProbe performRenderTiles = new PerformanceProfileProbe("performRenderTiles");
            static final PerformanceProfileProbe recalculateAnyGridStacks = new PerformanceProfileProbe("recalculateAnyGridStacks");
            static final PerformanceProfileProbe flattenAnyFoliage = new PerformanceProfileProbe("flattenAnyFoliage");
            static final PerformanceProfileProbe renderDebugPhysics = new PerformanceProfileProbe("renderDebugPhysics");
            static final PerformanceProfileProbe renderDebugLighting = new PerformanceProfileProbe("renderDebugLighting");
            static PerformanceProfileProbeList<IsoCell.s_performance.renderTiles.PperformRenderTilesLayer> performRenderTilesLayers = PerformanceProfileProbeList.construct(
                "performRenderTiles",
                8,
                IsoCell.s_performance.renderTiles.PperformRenderTilesLayer.class,
                IsoCell.s_performance.renderTiles.PperformRenderTilesLayer::new
            );

            static class PperformRenderTilesLayer extends PerformanceProfileProbe {
                final PerformanceProfileProbe renderIsoWater = new PerformanceProfileProbe("renderIsoWater");
                final PerformanceProfileProbe renderFloor = new PerformanceProfileProbe("renderFloor");
                final PerformanceProfileProbe renderPuddles = new PerformanceProfileProbe("renderPuddles");
                final PerformanceProfileProbe renderShore = new PerformanceProfileProbe("renderShore");
                final PerformanceProfileProbe renderSnow = new PerformanceProfileProbe("renderSnow");
                final PerformanceProfileProbe renderBlood = new PerformanceProfileProbe("renderBlood");
                final PerformanceProfileProbe vegetationCorpses = new PerformanceProfileProbe("vegetationCorpses");
                final PerformanceProfileProbe renderFloorShading = new PerformanceProfileProbe("renderFloorShading");
                final PerformanceProfileProbe renderShadows = new PerformanceProfileProbe("renderShadows");
                final PerformanceProfileProbe luaOnPostFloorLayerDraw = new PerformanceProfileProbe("luaOnPostFloorLayerDraw");
                final PerformanceProfileProbe minusFloorCharacters = new PerformanceProfileProbe("minusFloorCharacters");

                PperformRenderTilesLayer(String string) {
                    super(string);
                }
            }
        }
    }
}
